#include <bits/stdc++.h>
using namespace std;
map<string, string> mp;
char s[111], t[111];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    scanf("%s", t);
    string o(t);
    mp[o + ";"] = s;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%s", s);
    scanf("%s", t);
    string o(s);
    o += " ";
    o += t;
    o += " #";
    o += mp[t];
    puts(o.c_str());
  }
  return 0;
}
