#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000004;
long long p, q, x, l, r, y, z, i, j, k, n, m, t, d, c = 0, sum = 0;
long long int mn = 0x3f3f3f3f, len, cnt = 1, mx = -1000;
int a[51];
int dp[20][20] = {};
vector<int> v[20];
string s1, s2, s;
int main() {
  cin >> n >> m;
  string s1[n], s2[n], s3, s4, s5;
  for (int i = 0; i < n; i++) {
    cin >> s1[i] >> s2[i];
    s2[i] += ";";
  }
  for (int i = 0; i < m; i++) {
    cin >> s3 >> s4;
    for (int j = 0; j < n; j++)
      if (s4 == s2[j]) {
        cout << s3 << " " << s2[j] << " "
             << "#" << s1[j] << endl;
        break;
      }
  }
  return 0;
}
