#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 1e4 + 10;
int main() {
  int n, m;
  map<string, string> r, ans;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    b += ';';
    r[b] = a;
  }
  for (int j = 0; j < m; j++) {
    string c, d;
    cin >> c >> d;
    cout << c << " " << d << " #" << r[d] << endl;
  }
  return 0;
}
