#include <bits/stdc++.h>
using namespace std;
map<string, pair<string, int> > mp;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    string ip;
    cin >> ip;
    mp[ip].first = str;
    mp[ip].second = 1;
  }
  for (int i = 0; i < m; i++) {
    string str;
    cin >> str;
    string ip;
    cin >> ip;
    ip.pop_back();
    if (mp[ip].first.size() != 0) {
      cout << str << " " << ip << "; "
           << "#" << mp[ip].first << endl;
    }
  }
  return 0;
}
