#include <bits/stdc++.h>
using namespace std;
struct zuowei {
char zkz[20];
int sj;
int ks;
};
int main()
{
int n;
cin>>n;
zuowei a[n];
int i;
for (i=0;i<n;i++){
cin>>a[i].zkz >>a[i].sj >>a[i].ks ;
}
int n1;
cin>>n1;
int b,j;
for (i=0;i<n1;i++){
cin>>b;
for (j=0;j<n;j++){
if(a[j].sj ==b) cout<<a[j].zkz <<" "<<a[j].ks <<endl;
}
}
return 0;
}