#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  cin >> n >> m;
  map<string, string> m_ap;
  for (int i = 1; i <= n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    s2 = s2 + ";";
    m_ap[s2] = s1;
  }
  for (int i = 1; i <= m; i++) {
    string s3, s4;
    cin >> s3 >> s4;
    cout << s3 << " " << s4 << " "
         << "#" << m_ap[s4] << endl;
  }
  return 0;
}
