#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e6;
const int M = 4e3;
const int INF = 1 << 30;
map<string, string> ip;
string skh(string s) {
  string ns = "";
  for (int i = 0; i < ((int)(s).size()) - 1; i++) ns += s[i];
  return ns;
}
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s1s, s2s;
    cin >> s1s >> s2s;
    ip[s2s] = s1s;
  }
  for (int i = 0; i < m; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    s2 = skh(s2);
    cout << s1 << " " << s2 << "; #" << ip[s2] << '\n';
  }
  return 0;
}
