using System;
using System.Collections.Generic;
namespace ConsoleApp6
{
class ExamInfo
{
public string id;
public string try_no;
public string exam_no;
public ExamInfo(string id, string try_no, string exam_no)
{
this.id = id;
this.try_no = try_no;
this.exam_no = exam_no;
}
}
internal class Program
{
static void Main(string[] args)
{
List<ExamInfo> examInfos = new List<ExamInfo>();
int count = int.Parse(Console.ReadLine());
for (int i = 0; i < count; i++)
{
string line = Console.ReadLine();
string[] arr = line.Split(' ');
ExamInfo exam = new ExamInfo(arr[0], arr[1], arr[2]);
examInfos.Add(exam);
}
int query_count = int.Parse(Console.ReadLine());
string query = Console.ReadLine();
string[] query_arr = query.Split(' ');
for (int j = 0; j < query_arr.Length; j++)
{
ExamInfo examInfo = examInfos.Find(exam => exam.try_no == query_arr[j]);
if (examInfos != null)
{
Console.WriteLine($"{examInfo.id} {examInfo.exam_no}");
}
}
}
}
}