#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<std::pair<string, string> > serv;
vector<std::pair<string, string> > com;
int main() {
  cin >> n >> m;
  string name, ip;
  for (int i = 0; i < n; i++) {
    cin >> name >> ip;
    serv.push_back(make_pair(name, ip));
  }
  for (int i = 0; i < m; i++) {
    cin >> name >> ip;
    ip.erase(ip.find(';'), 1);
    for (int j = 0; j < n; j++) {
      if (ip == serv[j].second) {
        cout << name << " " << ip << "; #" << serv[j].first << "\n";
      }
    }
  }
  return 0;
}
