#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
map<string,string> a;
string x,y;
for(int i=0;i<n;i++){cin>>x>>y;a[y]=x;}
int m; cin >> m;
while(m--){cin>>x;cout<<(a.count(x)?a[x]:"NOT FOUND")<<'\n';}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtYWluKCl7CiAgICBpbnQgbjsgY2luID4+IG47CiAgICBtYXA8c3RyaW5nLHN0cmluZz4gYTsKICAgIHN0cmluZyB4LHk7CiAgICBmb3IoaW50IGk9MDtpPG47aSsrKXtjaW4+Png+Pnk7YVt5XT14O30KICAgIGludCBtOyBjaW4gPj4gbTsKICAgIHdoaWxlKG0tLSl7Y2luPj54O2NvdXQ8PChhLmNvdW50KHgpP2FbeF06Ik5PVCBGT1VORCIpPDwnXG4nO30KfQo=