#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
map<string, string> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  string k, v;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> v >> k;
    k = k + ";";
    mp[k] = v;
  }
  for (int i = 0; i < m; i++) {
    cin >> v >> k;
    cout << v << " " << k << " #" << mp[k] << endl;
  }
  return 0;
}
