#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string line;
  string deli = " ";
  getline(cin, line);
  map<string, string> ipMap;
  for (int i = 0; i < n; i++) {
    getline(cin, line);
    string name = line.substr(0, line.find(deli));
    string ip = line.substr(line.find(deli) + deli.length());
    ipMap[ip] = name;
  }
  ostringstream out;
  for (int i = 0; i < m; i++) {
    getline(cin, line);
    string command = line.substr(0, line.find(deli));
    size_t pos = line.find(deli) + deli.length();
    string ip =
        line.substr(line.find(deli) + deli.length(), line.length() - 1 - pos);
    out << line << " #" << ipMap[ip] << endl;
  }
  cout << out.str();
  return 0;
}
