#include <bits/stdc++.h>
using namespace std;
string s1[1005], s2[1005];
vector<string> out;
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s1[i] >> s2[i];
    s2[i].append(";");
  }
  for (int i = 0; i < m; i++) {
    string s3, s4;
    cin >> s3 >> s4;
    for (int j = 0; j < n; j++) {
      if (s4.compare(s2[j]) == 0) {
        string neu;
        neu.append(s3);
        neu.append(" ");
        neu.append(s4);
        neu.append(" #");
        neu.append(s1[j]);
        out.push_back(neu);
        break;
      }
    }
  }
  for (int i = 0; i < out.size(); i++) cout << out[i] << endl;
}
