#include <bits/stdc++.h>
using namespace std;
map<string, string> mp;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  while (n--) {
    string a, b;
    cin >> a >> b;
    mp[b + ";"] = a;
  }
  while (m--) {
    string a, b;
    cin >> a >> b;
    cout << a << " " << b << " #" << mp[b] << endl;
  }
  return 0;
}
