#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, q, qq;
  cin >> n >> m;
  map<string, string> p;
  string a[n], b[n], c[m], d[m];
  for (q = 0; q < n; q++) {
    cin >> a[q] >> b[q];
    p[b[q]] = a[q];
  }
  for (qq = 0; qq < m; qq++) {
    cin >> c[qq] >> d[qq];
    d[qq].pop_back();
  }
  for (qq = 0; qq < m; qq++) {
    cout << c[qq] << " " << d[qq] << "; #" << p[d[qq]] << endl;
  }
}
