#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string name[n];
  string nameCheck;
  string ip[n];
  string ipCheck[m];
  for (int i = 0; i < n; i++) {
    cin >> name[i] >> ip[i];
    ip[i] += ';';
  }
  for (int i = 0; i < m; i++) {
    cin >> nameCheck >> ipCheck[i];
    for (int j = 0; j < n; j++) {
      if (ipCheck[i] == ip[j]) {
        cout << nameCheck << ' ' << ip[j] << " #" << name[j] << "\n";
      }
    }
  }
  return 0;
}
