#include <bits/stdc++.h>
using namespace std;
vector<string> v;
vector<string> v2;
int main() {
  string s, s2;
  int n, m, l;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> s2;
    s2.insert(s2.length(), 1, ';');
    v.push_back(s);
    v2.push_back(s2);
  }
  for (int i = 0; i < m; i++) {
    cin >> s >> s2;
    for (int j = 0; j < n; j++) {
      if (v2[j] == s2) {
        cout << s << " " << v2[j] << " "
             << "#" << v[j] << endl;
        break;
      }
    }
  }
  return 0;
}
