#include <bits/stdc++.h>
using namespace std;
int main() {
  map<pair<int, int>, string> mm;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    char r;
    int a, b, c, d;
    string g;
    cin >> g >> a >> r >> b >> r >> c >> r >> d;
    int a1 = ((a << 8) | b);
    int b1 = ((c << 8) | d);
    mm[make_pair(a1, b1)] = g;
  }
  vector<string> ans;
  for (int i = 0; i < m; ++i) {
    stringstream ss;
    char r;
    int a, b, c, d;
    string g;
    cin >> g >> a >> r >> b >> r >> c >> r >> d >> r;
    int a1 = ((a << 8) | b);
    int b1 = ((c << 8) | d);
    cout << g << " " << a << "." << b << "." << c << "." << d << "; #"
         << mm[make_pair(a1, b1)] << "\n";
    string f;
    ss >> f;
    ans.emplace_back(f);
  }
  return 0;
}
