#include <bits/stdc++.h>
using namespace std;
map<string, string> M;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string name, ip;
    cin >> name >> ip;
    M[ip] = name;
  }
  for (int i = 0; i < m; i++) {
    string cmd, ip;
    cin >> cmd >> ip;
    ip.pop_back();
    cout << cmd << " " << ip << "; #" << M[ip] << endl;
  }
}
