#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, m;
  cin >> n >> m;
  map<string, string> mp, mp1;
  string s[n], s1[n], str[m], str1[m];
  for (long long i = 0; i < n; i++) {
    cin >> s[i] >> s1[i];
    s1[i] += ';';
    mp[s1[i]] = s[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> str[i] >> str1[i];
    mp1[str1[i]] = str[i];
  }
  vector<string> v;
  for (long long i = 0; i < m; i++) {
    cout << str[i] << " " << str1[i] << " "
         << "#" << mp[str1[i]] << "\n";
  }
}
