#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> ip;
  map<string, string>::iterator it;
  int n, m;
  string s, i;
  cin >> n >> m;
  while (n--) {
    cin >> s >> i;
    ip[i] = s;
  }
  while (m--) {
    cin >> s >> i;
    i.erase(i.find(';'));
    cout << s << " " << i << "; #" << ip[i] << endl;
  }
}
