#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  size_t n, m;
  std::cin >> n >> m;
  std::map<std::string, std::string> names;
  for (size_t i = 0; i < n; ++i) {
    std::string name, ip;
    std::cin >> name >> ip;
    names[ip] = name;
  }
  for (size_t i = 0; i < m; ++i) {
    std::string command, ip;
    std::cin >> command >> ip;
    std::cout << command << ' ' << ip << " #"
              << names[ip.substr(0, ip.size() - 1)] << '\n';
  }
}
