#include <bits/stdc++.h>
using namespace std;
int const diff = 'a' - 'A';
int const oo = 2147483647;
long long const loo = 1e18 + 9;
struct ser {
  string name;
  int fir, sec, trd, fth;
};
ser arr[1010];
int main() {
  long long n;
  cin >> n;
  ;
  long long m;
  cin >> m;
  ;
  for (int i = 0; i < n; i++) {
    char h;
    cin >> arr[i].name;
    cin >> arr[i].fir >> h;
    cin >> arr[i].sec >> h;
    cin >> arr[i].trd >> h;
    cin >> arr[i].fth;
  }
  string g;
  char h;
  int fr[5];
  for (int i = 0; i < m; i++) {
    cin >> g;
    cin >> fr[0] >> h;
    cin >> fr[1] >> h;
    cin >> fr[2] >> h;
    cin >> fr[3] >> h;
    cout << g << ' ' << fr[0] << '.' << fr[1] << '.' << fr[2] << '.';
    cout << (fr[3]) << "; #";
    for (int j = 0; j < n; j++) {
      if (fr[0] == arr[j].fir && fr[1] == arr[j].sec && fr[2] == arr[j].trd &&
          fr[3] == arr[j].fth) {
        cout << arr[j].name << endl;
        j = n;
      }
    }
  }
}
