using System.Collections.Generic;
public static void Main(string[] args)
using (StreamReader sr = new StreamReader("input.txt"))
using (StreamWriter sw = new StreamWriter("output.txt")) {
Dictionary<int, List<int>> CountryData = new Dictionary<int, List<int>>();
int n = int.Parse(sr.ReadLine());
for (int i = 0; i < n; i++)
string[] s = sr.ReadLine().Split(' ');
int countryCode = int.Parse(s[0]);
CountryData.Add(countryCode, new List<int>());
for (int k = 0; k < int.Parse(s[1]); k++)
int phoneCode = int.Parse(sr.ReadLine());
CountryData[countryCode].Add(phoneCode);
int m = int.Parse(sr.ReadLine());
for (int i = 0; i < m; i++)
string phone = Console.ReadLine();
foreach (int countryCode in CountryData.Keys)
foreach (int phoneCode in CountryData[countryCode])
if (phone.IndexOf(countryCode.ToString() + phoneCode.ToString()) == 0) {
AddPhone(countryCode, phoneCode, phone, sw);
Console.WriteLine("Incorrect");
public static void AddPhone(int countryCode, int phoneCode, string phone, StreamWriter writer)
phone = phone.Remove(0, countryCode.ToString().Length + phoneCode.ToString().Length);
phone = phone.Insert(2, "-");
phone = phone.Insert(3, "-");
phone = phone.Insert(2, "-");
phone = phone.Insert(5, "-");
phone = phone.Insert(3, "-");
phone = phone.Insert(6, "-");
writer.WriteLine("+" + countryCode.ToString() + "(" + phoneCode.ToString() + ")" + phone);