#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979323846;
const long long mod = 1e9 + 7;
const long long N = 5e5 + 500;
const long long INF = 1e9 + 1;
long long n, m;
map<string, string> ss;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) {
    string s, t;
    cin >> s >> t;
    ss[t] = s;
  }
  for (long long i = 1; i <= m; ++i) {
    string s, t;
    cin >> s >> t;
    t.pop_back();
    cout << s << " " << t << "; #" << ss[t] << endl;
  }
  return 0;
}
