#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n, m;
    cin >> n >> m;
    map<string, string> make_pair;
    string a, b;
    for (long long int i = 0; i < n; i++) {
      cin >> a >> b;
      b += ';';
      make_pair[b] = a;
    }
    for (long long int i = 0; i < m; i++) {
      cin >> a >> b;
      cout << a << " " << b << " #" << make_pair[b] << '\n';
    }
  }
  return 0;
}
