#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
long long const nrmax = 1e18;
map<string, string> q;
string a, b;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, i;
  cin >> n >> m;
  for (i = 1; i <= n; ++i) {
    cin >> a >> b;
    b += ';';
    q[b] = a;
  }
  for (i = 1; i <= m; ++i) {
    cin >> a >> b;
    cout << a << " " << b << " "
         << "#" << q[b] << '\n';
  }
  in.close();
  out.close();
  return 0;
}
