#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<string, string> mp;
  while (n--) {
    string name, ip;
    cin >> name >> ip;
    mp[ip] = name;
  }
  while (m--) {
    string s1, ip;
    cin >> s1 >> ip;
    ip.pop_back();
    cout << s1 << " " << ip << "; #" << mp[ip] << endl;
  }
}
