#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  map<string, string> mp;
  for (int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    mp[s2] = s1;
  }
  while (m--) {
    string s3, s4;
    cin >> s3 >> s4;
    s4.pop_back();
    cout << s3 << " " << s4 << "; #" << mp[s4] << endl;
  }
}
