#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> name(n);
  vector<string> ng(n);
  for (int i = 0; i < n; ++i) {
    cin >> name[i] >> ng[i];
    ng[i] += ";";
  }
  for (int i = 0; i < m; ++i) {
    string s1, ip;
    cin >> s1 >> ip;
    cout << s1 << " " << ip << " #"
         << name[find(ng.begin(), ng.end(), ip) - ng.begin()] << endl;
  }
}
