#include <bits/stdc++.h>
using namespace std;
string a[100000], b[100000], c[100000], d[100000];
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> c[i] >> d[i];
    d[i].erase(d[i].find(";"), 1);
  }
  for (int i = 1; i <= m; i++) {
    for (int u = 1; u <= n; u++) {
      if (d[i] == b[u]) {
        cout << c[i] << " " << d[i] << "; #" << a[u] << endl;
      }
    }
  }
  return 0;
}
