#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string> > registry;
vector<pair<string, string> > commands;
int main() {
  ios::sync_with_stdio(false);
  long long n = 0, m = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string name, ip;
    cin >> name >> ip;
    registry.push_back(make_pair(name, ip));
  }
  for (int i = 0; i < m; i++) {
    string command, ip;
    cin >> command >> ip;
    ip = ip.substr(0, ip.size() - 1);
    commands.push_back(make_pair(command, ip));
  }
  for (int i = 0; i < m; i++) {
    string command_ip = commands[i].second;
    long long index = 0;
    for (int j = 0; j < n; j++) {
      if (command_ip == registry[j].second) {
        index = j;
        break;
      }
    }
    cout << commands[i].first << " " << command_ip << ";"
         << " #" << registry[index].first << endl;
  }
  return 0;
}
