#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  map<string, string> mp;
  for (int i = 0; i < n; i++) {
    string s, name;
    cin >> name >> s;
    s += ';';
    mp[s] = name;
  }
  for (int i = 0; i < m; i++) {
    string s, name;
    cin >> name >> s;
    cout << name << " " << s << " #" << mp[s] << endl;
  }
  return 0;
}
