#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m; cin >> n >> m;
string s,c,i;
unordered_map<string,string> ser;
for(int j=0;j<n;j++){
cin >> s >> i;
ser.emplace(i+";",s);
}
for(int j=0;j<m;j++){
cin >> c >> i;
cout << c << " " << i << " #" << ser.find(i)->second << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCBuLG07CWNpbiA+PiBuID4+IG07CglzdHJpbmcgcyxjLGk7Cgl1bm9yZGVyZWRfbWFwPHN0cmluZyxzdHJpbmc+IHNlcjsKCQoJZm9yKGludCBqPTA7ajxuO2orKyl7CgkJY2luID4+IHMgPj4gaTsKCQlzZXIuZW1wbGFjZShpKyI7IixzKTsKCX0KCWZvcihpbnQgaj0wO2o8bTtqKyspewoJCWNpbiA+PiBjID4+IGk7CgkJY291dCA8PCBjIDw8ICIgIiA8PCBpIDw8ICIgIyIgPDwgc2VyLmZpbmQoaSktPnNlY29uZCA8PCBlbmRsOwoJfQoJcmV0dXJuIDA7Cn0=
MyA1Cmdvb2dsZSA4LjguOC44CmNvZGVmb3JjZXMgMjEyLjE5My4zMy4yNwpzZXJ2ZXIgMTM4LjE5Ny42NC41NwpyZWRpcmVjdCAxMzguMTk3LjY0LjU3OwpibG9jayA4LjguOC44OwpjZiAyMTIuMTkzLjMzLjI3Owp1bmJsb2NrIDguOC44Ljg7CmNoZWNrIDEzOC4xOTcuNjQuNTc7Cg==
3 5
google 8.8.8.8
codeforces 212.193.33.27
server 138.197.64.57
redirect 138.197.64.57;
block 8.8.8.8;
cf 212.193.33.27;
unblock 8.8.8.8;
check 138.197.64.57;