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