#include <bits/stdc++.h>
using namespace std;
int i;
long n, m;
map<string, string> mp;
string x, ip;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> x >> ip;
    mp[ip] = x;
  }
  while (m--) {
    cin >> x >> ip;
    ip = ip.substr(0, ip.length() - 1);
    cout << x << " " << ip << ";"
         << " "
         << "#" << mp[ip] << endl;
  }
  return 0;
}
