#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  pair<string, string> p[m];
  map<string, string> mp1;
  while (n--) {
    string a, b;
    cin >> a >> b;
    mp1[b] = a;
  }
  for (int i = 0; i < m; i++) {
    string c, d;
    cin >> c >> d;
    d.erase(d.begin() + d.length() - 1, d.end());
    p[i].first = c;
    p[i].second = d;
  }
  for (int i = 0; i < m; i++)
    cout << p[i].first << " " << p[i].second << "; #" << mp1[p[i].second]
         << endl;
  return 0;
}
