#include <bits/stdc++.h>
using namespace std;
map<string, string> mp;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string x, y;
    cin >> x >> y;
    y += ";";
    mp[y] = x;
  }
  for (int i = 0; i < m; i++) {
    string x, y;
    cin >> x >> y;
    cout << x << " " << y << " #" << mp[y] << endl;
  }
  return 0;
}
