#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  getchar();
  map<string, string> mp;
  while (n--) {
    string str;
    getline(cin, str);
    stringstream s(str);
    string s1, s2;
    for (int i = 0; i < 2; i++) {
      if (i == 0) {
        s >> s1;
      } else {
        s >> s2;
      }
    }
    s2 += ';';
    mp[s2] = s1;
  }
  while (m--) {
    string str;
    getline(cin, str);
    stringstream s(str);
    string s1, s2;
    for (int i = 0; i < 2; i++) {
      if (i == 0) {
        s >> s1;
      } else {
        s >> s2;
      }
    }
    cout << s1 << " " << s2 << " #" << mp[s2] << endl;
  }
}
