#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<string, string> mp;
  for (int i = 0; i < n; i++) {
    string name, ip;
    cin >> name >> ip;
    mp[ip] = name;
  }
  while (m--) {
    string s, ipAdress;
    cin >> s >> ipAdress;
    ipAdress.pop_back();
    cout << s << " " << ipAdress << "; #" << mp[ipAdress] << endl;
  }
}
