#include <bits/stdc++.h>
using namespace std;
string int_to_string(int item) {
  stringstream ss;
  ss << item;
  return ss.str();
}
int string_to_int(string item) {
  stringstream ss(item);
  int x = 0;
  ss >> x;
  return x;
}
int char_to_int(char item) { return ((int)item - 48); }
int main() {
  long long int n, m, i, j;
  cin >> n >> m;
  string sname, sip, scommand;
  vector<string> name;
  vector<string> ip;
  vector<string> command;
  for (i = 0; i < n; i++) {
    cin >> sname >> sip;
    name.push_back(sname);
    ip.push_back(sip);
  }
  for (i = 0; i < m; i++) {
    cin >> scommand >> sip;
    int h = sip.length();
    h--;
    sip.erase(sip.begin() + h);
    for (j = 0; j < n; j++) {
      if (sip == ip[j]) {
        cout << scommand << " " << ip.at(j) << ";"
             << " #" << name.at(j) << endl;
      }
    }
  }
}
