#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  map<string, string> mp;
  cin >> n >> m;
  string name, ip;
  string name1, ip1;
  for (int i = 0; i < n; i++) {
    cin >> name >> ip;
    mp[ip] = name;
  }
  for (int i = 0; i < m; i++) {
    cin >> name1 >> ip1;
    cout << name1 << " " << ip1 << " #" << mp[ip1.substr(0, ip1.size() - 1)]
         << endl;
  }
  return 0;
}
