#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string name[n + 5], ip[n + 5];
  string command[m + 5], ip1[m + 5];
  for (int i = 1; i <= n; i++) {
    cin >> name[i] >> ip[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> command[i] >> ip1[i];
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (ip1[i] == ip[j] + ';') {
        cout << command[i] << " " << ip1[i] << " "
             << "#" << name[j] << endl;
        ;
      }
    }
  }
  return 0;
}
