#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  char name[n][11], name_ips[n][18], comm[m][11], comm_ips[m][18];
  for (long long i = 0; i < n; i++) {
    cin >> name[i];
    cin >> name_ips[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> comm[i];
    cin >> comm_ips[i];
  }
  for (long long i = 0; i < m; i++) {
    long long x = strlen(comm_ips[i]) - 1;
    comm_ips[i][x] = '\0';
  }
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n; j++) {
      if (strcmp(comm_ips[i], name_ips[j]) == 0) {
        cout << comm[i] << " " << comm_ips[i] << "; #" << name[j];
      }
    }
    cout << endl;
  }
  return 0;
}
