#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932384;
signed main() {
  long long n, m;
  cin >> n >> m;
  map<string, string> mp;
  string s1, s2;
  for (long long i = 0; i < n; i++) {
    cin >> s1 >> s2;
    mp[s2] = s1;
  }
  string s3, s4;
  for (long long i = 0; i < m; i++) {
    cin >> s3 >> s4;
    s4.erase(s4.begin() + s4.size() - 1);
    cout << s3 << " " << s4 << ";"
         << " "
         << "#" << mp[s4] << endl;
  }
}
