#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<string, string> a;
  for (int i = 0; i < n; i++) {
    string b, c;
    cin >> b >> c;
    a[c] = b;
  }
  for (int i = 0; i < m; i++) {
    string b, c;
    cin >> b >> c;
    c.erase(c.end() - 1);
    cout << b << " " << c << "; #" << a[c] << "\n";
  }
  return 0;
}
