#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m; cin >> n >> m;
string s,c,i;
map<string,string> ser;
for(int j=0;j<n;j++){
cin >> s >> i;
ser.insert(make_pair(i,s));
}
for(int j=0;j<m;j++){
cin >> c >> i;
cout << c << " " << i << " #";
auto it = ser.find(i);
cout << it->second << endl;
// cout << c << " " << i << " #" << it->second << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCBuLG07CWNpbiA+PiBuID4+IG07CglzdHJpbmcgcyxjLGk7CgltYXA8c3RyaW5nLHN0cmluZz4gc2VyOwoJZm9yKGludCBqPTA7ajxuO2orKyl7CgkJY2luID4+IHMgPj4gaTsKCQlzZXIuaW5zZXJ0KG1ha2VfcGFpcihpLHMpKTsKCX0KCWZvcihpbnQgaj0wO2o8bTtqKyspewoJCWNpbiA+PiBjID4+IGk7CgkJY291dCA8PCBjIDw8ICIgIiA8PCBpIDw8ICIgIyI7CgkJYXV0byBpdCA9IHNlci5maW5kKGkpOwoJCWNvdXQgPDwgaXQtPnNlY29uZCA8PCBlbmRsOwoJCS8vIGNvdXQgPDwgYyA8PCAiICIgPDwgaSA8PCAiICMiIDw8IGl0LT5zZWNvbmQgPDwgZW5kbDsKCX0KCXJldHVybiAwOwp9