#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Student{
ll num;
int shiji;
int kaoshi;
};
int main(){
int n;
cin>>n;
vector<Student> ve(n);
for(int i=0;i<n;i++){
cin>>ve[i].num>>ve[i].shiji>>ve[i].kaoshi;
}
int m;
cin>>m;
while(m--){
int a;
cin>>a;
for(auto v:ve)if(a==v.shiji)cout<<v.num<<' '<<v.kaoshi<<endl;
}
return 0;
}