#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> mp;
  int n, m;
  string s, s2;
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s >> s2;
    mp[s2] = s;
  }
  for (int i = 0; i < m; i++) {
    cin >> s >> s2;
    s2.pop_back();
    cout << s << " " << s2 << "; #" << mp[s2] << "\n";
  }
  return 0;
}
