#include <bits/stdc++.h>
using namespace std;
int f[20];
int main() {
  int n, m;
  cin >> n >> m;
  map<string, string> servers;
  for (int i = 0; i < n; i++) {
    string name;
    string ip;
    cin >> name >> ip;
    servers[ip] = name;
  }
  for (int i = 0; i < m; i++) {
    string command;
    string ip;
    cin >> command >> ip;
    ip.pop_back();
    cout << command << ' ' << ip << "; #" << servers[ip] << endl;
  }
  return 0;
}
