#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
unordered_map<int, pair<string, int>> hash;
while (n--)
{
string s;
int a, b; cin >> s >> a >> b;
hash[a] = {s, b};
}
cin >> n;
while (n--)
{
int x; cin >> x;
cout << hash[x].first << ' ' << hash[x].second << endl;
}
return 0;
}