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