#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  string a[2 * n], b[2 * m];
  for (int i = 0; i < 2 * n; i += 2) {
    cin >> a[i] >> a[i + 1];
  }
  for (int i = 0; i < 2 * m; i += 2) {
    cin >> b[i] >> b[i + 1];
  }
  for (int i = 1; i < 2 * m; i += 2) {
    for (int j = 1; j < 2 * n; j += 2) {
      string x = b[i];
      if ((x.erase(x.size() - 1)).compare(a[j]) == 0) {
        cout << b[i - 1] << " " << b[i] << " #" << a[j - 1];
      }
    }
    cout << "\n";
  }
}
