#include <bits/stdc++.h>
using namespace std;
int N, M;
map<string, string> m1;
int main() {
  cin >> N >> M;
  string s1;
  string s2;
  for (int i = 1; i <= N; i++) {
    cin >> s1;
    cin >> s2;
    m1[s2] = s1;
  }
  for (int i = 1; i <= M; i++) {
    cin >> s1;
    cin >> s2;
    s2.erase(s2.begin() + s2.size() - 1);
    cout << s1 << " ";
    cout << s2 << "; #" << m1[s2] << endl;
  }
  return 0;
}
