#include <bits/stdc++.h>
using namespace std;
map<string, string> k;
string s, p;
int n, m;
int main() {
  cin >> n >> m;
  while (n--) cin >> s >> p, k[p] = s;
  while (m--)
    cin >> s >> p, p.pop_back(), cout << s << ' ' << p << "; #" << k[p] << endl;
}
