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