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