#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 8;
map<string, string> mp;
string s1, s2;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, i, j;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> s1 >> s2;
    s2 += ';';
    mp[s2] = s1;
  }
  for (i = 0; i < m; i++) {
    cin >> s1 >> s2;
    cout << s1 << " " << s2 << " #" << mp[s2] << "\n";
  }
  return 0;
}
