As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.

 [Image] 

Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.

Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.


-----Input-----

The first line of input contains two integers n and m (1 ≤ n, m ≤ 1000).

The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≤ |name| ≤ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct.

The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≤ |command| ≤ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers.


-----Output-----

Print m lines, the commands in the configuration file after Dustin did his task.


-----Examples-----
Input
2 2
main 192.168.0.2
replica 192.168.0.1
block 192.168.0.1;
proxy 192.168.0.2;

Output
block 192.168.0.1; #replica
proxy 192.168.0.2; #main

Input
3 5
google 8.8.8.8
codeforces 212.193.33.27
server 138.197.64.57
redirect 138.197.64.57;
block 8.8.8.8;
cf 212.193.33.27;
unblock 8.8.8.8;
check 138.197.64.57;

Output
redirect 138.197.64.57; #server
block 8.8.8.8; #google
cf 212.193.33.27; #codeforces
unblock 8.8.8.8; #google
check 138.197.64.57; #server

Difficulty: EASY
Tags: String algorithms

Implementation

Starter code:

Solutions:
(n, m) = map(int, input().split())
a = []
b = []
ans = []
p = []
for i in range(n):
	(c, d) = map(str, input().split())
	d += ';'
	a.append(c)
	a.append(d)
for i in range(m):
	b.append(list(map(str, input().split())))
for i in range(m):
	p.append(b[i][0])
	p.append(b[i][1])
	p.append('#' + a[a.index(b[i][1]) - 1])
	ans.append(p)
	p = []
for i in range(m):
	print(*ans[i])


Dustin = {}
(n, k) = input().rstrip().split()
for i in range(int(n)):
	(site, ip) = input().split()
	if ip not in Dustin:
		Dustin[ip] = site
for j in range(int(k)):
	(inst, ip1) = input().split()
	for (o, m) in Dustin.items():
		if ip1 == o + ';':
			print(inst + ' ' + ip1 + ' #' + m)
			break


(n, m) = tuple(map(int, input().split()))
dic = dict()
query = ''
for i in range(n + m):
	(fun, ip) = input().split()
	if ip[:-1] in dic:
		query += fun + ' ' + ip + ' #' + dic[ip[:-1]] + '\n'
	else:
		dic[ip] = fun
print(query)


a = [int(q) for q in input().strip().split()]
b = {}
for k in range(a[0]):
	d = input().split()
	b[d[1]] = d[0]
for k in range(a[1]):
	d = input().split()
	d[1] = d[1][0:len(d[1]) - 1]
	print(d[0] + ' ' + d[1] + '; #' + b[d[1]])


(n, m) = map(int, input().split())
d = {}
for j in range(n):
	s = input().strip().split()
	d[s[1] + ';'] = s[0]
a = ''
for k in range(m):
	s = input().strip().split()
	a = a + s[0] + ' ' + s[1] + ' #' + d[s[1]] + '\n'
a = a.rstrip('\n')
print(a)


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	(p, q) = input().split()
	d[q] = d.get(q, '') + p
for i in range(m):
	(p, q) = input().split()
	s = q[:-1]
	print(p, q, '#' + d[s])


def second(num):
	return num[1]
(n, m) = map(int, input().split())
adr = []
for i in range(n):
	(name, ip) = map(str, input().split())
	new_ip = ''
	for j in range(len(ip)):
		if ip[j] != '.':
			new_ip += ip[j]
	ip = new_ip
	adr.append([name, ip])
adr.sort(key=second)
for i in range(m):
	(smth, ip) = map(str, input().split())
	ip = ip[:len(ip) - 1]
	new_ip = ''
	old = ip
	for j in range(len(ip)):
		if ip[j] != '.':
			new_ip += ip[j]
	ip = new_ip
	left = -1
	right = len(adr)
	while right - left > 1:
		mid = (right + left) // 2
		if adr[mid][1] >= ip:
			right = mid
		else:
			left = mid
	print(smth, old, end='')
	print(';', '#', end='')
	print(adr[right][0])


(n, m) = [int(x) for x in input().split()]
servers = []
commands = []
dictionary = {}
for i in range(n):
	(name, ip) = [x for x in input().split()]
	servers.append((name, ip))
	dictionary.update({ip: name})
for i in range(m):
	(command, ip) = [x for x in input().split()]
	ip = ip[:len(ip) - 1]
	commands.append((command, ip))
for i in range(m):
	print(f'{commands[i][0]} {commands[i][1]}; #{dictionary[commands[i][1]]}')


(n, m) = input().split()
n = int(n)
m = int(m)
ipDic = {}
for i in range(0, n):
	(name, ip) = input().split()
	ipDic[ip] = name
cmdList = []
for i in range(0, m):
	(command, ip) = input().split()
	oIP = ip
	ip = ip[0:len(ip) - 1]
	result = command + ' ' + oIP + ' #' + ipDic[ip]
	cmdList.append(result)
for i in cmdList:
	print(i)


(a, b) = map(int, input().split())
d = {}
for i in range(a):
	(x, y) = input().split()
	d[y] = x
for i in range(b):
	(q, w) = input().split()
	print(q, w, '#' + d[w[:len(w) - 1]])


(n, m) = list(map(int, input().split()))
d = {}
while n:
	s = input().split(' ')
	d[s[-1] + ';'] = s[0]
	n = n - 1
while m:
	ss = input()
	print(ss.split(' ')[0] + ' ' + ss.split(' ')[-1] + ' #' + d[ss.split(' ')[-1]])
	m = m - 1


(n, m) = map(int, input().split())
(l, g) = ([], [])
for _ in range(n):
	l.append(input().split())
for _ in range(m):
	g.append(input().split())
k = []
for i in g:
	c = [int(x) for x in i[1][:len(i[1]) - 1].split('.')]
	for j in l:
		d = [int(y) for y in j[1].split('.')]
		if c == d:
			k.append(i[0] + ' ' + i[1] + ' #' + j[0])
print('\n'.join(k))


(n, m) = map(int, input().strip().split(' '))
import collections
s = collections.defaultdict(lambda : '')
for i in range(n):
	(server, ip) = input().strip().split(' ')
	s[ip] = server
for i in range(m):
	(cmd, ip) = input().strip().split(' ')
	print(cmd, ip, '#', end='')
	print(s[ip[:-1]])


(n, m) = map(int, input().strip().split()[:2])
s = []
ser = []
for x in range(n):
	s.append(input().strip().split())
for x in range(m):
	ser.append(input().strip().split())
for x in ser:
	for y in s:
		if x[1][:len(x[1]) - 1] == y[1]:
			print(*x, end='')
			print(' #' + y[0])


(n, m) = input().split()
n = int(n)
m = int(m)
arrayStringName = []
arrayStringIp = []
for _ in range(n):
	(name, ip) = input().split()
	name = str(name)
	ip = str(ip)
	arrayStringName.append(name)
	arrayStringIp.append(ip)
for i in range(m):
	ip = ''
	commandIp = str(input())
	for j in range(len(commandIp)):
		if commandIp[j].isnumeric() == True or commandIp[j] == '.':
			ip += commandIp[j]
	getIndexInArray = arrayStringIp.index(ip)
	print(commandIp + ' #' + arrayStringName[getIndexInArray])


(a, b) = input().split()
(a, b) = (int(a), int(b))
m = a + b
serv = {}
for i in range(a):
	(name, ip) = input().split()
	ip = ip + ';'
	serv[ip] = name
for i in range(b):
	(mn, ip) = input().split()
	print(mn, ip, '#' + serv[ip])


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	s = input()
	s = s.split()
	d[s[1]] = s[0]
ans = []
for i in range(m):
	s = input()
	s = s.split()
	ip = s[1][:-1]
	ans.append('{} #{}'.format(' '.join(s), d[ip]))
for a in ans:
	print(a)


n = list(map(int, input().split()))
l = []
p = []
for i in range(n[0]):
	m = list(map(str, input().split()))
	m[1] = m[1] + ';'
	l.append(m)
for o in range(n[1]):
	b = list(map(str, input().split()))
	p.append(b)
for u in range(n[1]):
	for e in range(n[0]):
		if l[e][1] == p[u][1]:
			print(p[u][0], end=' ')
			print(p[u][1], end='')
			print(' #', end='')
			print(l[e][0])


s = input().split()
(n, m) = (int(s[0]), int(s[1]))
d = {}
for i in range(n):
	s = input().split()
	(name, ip) = (s[0], s[1] + ';')
	d[ip] = name
for i in range(m):
	s = input().split()
	(name, ip) = (s[0], s[1])
	print('{} {} #{}'.format(name, ip, d[ip]))


nm = input().split()
n = int(nm[0])
m = int(nm[1])
mp = {}
for i in range(n):
	(v, k) = input().split()
	mp[k] = v
for i in range(m):
	(c, ip) = input().split()
	ip = ip[0:-1]
	name = mp[ip]
	print('{} {}; #{}'.format(c, ip, name))


(n, m) = [int(i) for i in input().split()]
d = dict()
for i in range(n):
	(a, b) = [i.rstrip() for i in input().split()]
	d[b] = a
for i in range(m):
	(a, b) = [i.rstrip() for i in input().split()]
	b = b[:-1]
	print(a, ' ', b, '; #', d[b], sep='')


import sys
(n, m) = [int(x) for x in input().split(' ')]
servers = dict()
commands = []
res = []
for _ in range(n):
	(x, y) = input().split(' ')
	servers[y] = x
for _ in range(m):
	s = input()
	commands.append(s)
	(x, y) = s.split(' ')
	res.append(s + ' #' + servers[y.replace(';', '')])
for r in res:
	print(r)


(n, m) = [int(x) for x in input().split()]
myMap = {}
for i in range(n):
	(name, ip) = [s for s in input().split(' ')]
	myMap[ip] = name
for i in range(m):
	(command, ip) = [s for s in input().split(' ')]
	print(command, end=' ')
	ip = ip.replace(';', '')
	print(ip, end='; #')
	print(myMap[ip])


(m, n) = map(int, input().split())
se = []
c = []
for i in range(m):
	se.append(list(map(str, input().split())))
for j in range(n):
	c.append(list(map(str, input().split())))
for t in range(n):
	for g in range(m):
		if c[t][1][:-1] == se[g][1]:
			print(' '.join(c[t]), '#' + se[g][0])


(n, m) = input().split()
n = eval(n)
m = eval(m)
dict = {}
for i in range(n):
	(x, y) = input().split()
	dict[y] = x
for i in range(m):
	(x, y) = input().split()
	s = dict[y[:-1]]
	print(x + ' ' + y + ' #' + s)


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	x = list(input().split())
	d[x[1]] = x[0]
for j in range(m):
	y = list(input().split())
	print(*y, '#' + d[y[1][:-1]])


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	t = input()
	t = t.split()
	s = t[1]
	d[s] = t[0]
for i in range(m):
	t = input()
	s = t.split()[1][:-1]
	t += ' #' + d[s]
	print(t)


(n, m) = input().split()
n = int(n)
m = int(m)
name = []
ips = []
res = []
k = 0
for i in range(n):
	(a, b) = input().split()
	name.append(str(a))
	ips.append(str(b))
for i in range(m):
	(a, b) = input().split()
	b = b[:-1]
	for j in range(n):
		if ips[j] == b:
			print('{} {}; #{}'.format(a, b, name[j]))


(n, m) = map(int, input().split())
l = []
p = []
k = []
for i in range(n):
	(a, b) = map(str, input().split())
	l.append(a)
	p.append(b + ';')
for i in range(m):
	(a, b) = map(str, input().split())
	k.append(a)
	k.append(b)
for i in range(1, len(k), 2):
	for j in p:
		if k[i] == j:
			print(k[i - 1], k[i], '#' + l[p.index(j)])
			break


(n, m) = map(int, input().split())
l = []
l3 = []
for i in range(n):
	(a, b) = input().split()
	l3.append(a)
	l.append(b)
for i in range(m):
	(a, b) = input().split()
	c = b[:-1]
	new = a + ' ' + b + ' #'
	print(new, *l3[l.index(c)], sep='')


(n, m) = list(map(int, input().split()))
g = {}
for i in range(n):
	(na, ip) = input().split()
	g[ip] = na
for i in range(m):
	a = input()
	(c, ip) = a.split()
	print(a + ' #' + g[ip[:-1]])


(n, m) = map(int, input().split())
dict1 = {}
for i in range(n):
	(a, b) = map(str, input().split())
	dict1[b] = a
arr1 = []
for i in range(m):
	(a, b) = map(str, input().split())
	s1 = ''
	s1 += a + ' ' + b + ' #' + dict1[b[:-1]]
	arr1.append(s1)
for i in arr1:
	print(i)


def main():
	(n, m) = map(int, input().split())
	server = {}
	for _ in range(n):
		(s, ip) = map(str, input().split())
		server[ip] = s
	for _ in range(m):
		(c, ip) = map(str, input().split())
		print(c, ip, '#', end='')
		print(server[ip[:-1]])
main()


(servers, commands) = map(int, input().split())
lst1 = []
for a in range(servers):
	lst = input().split()
	lst1.append(lst)
for i in range(commands):
	stat = input().split()
	for j in range(servers):
		if stat[1][:-1] == lst1[j][1]:
			print(stat[0] + ' ' + stat[1] + ' ' + '#' + lst1[j][0])


nm = input()
[n, m] = [int(x) for x in nm.split(' ')]
d = {}
for i in range(n):
	line = input()
	items = line.split(' ')
	d[items[1]] = items[0]
for i in range(m):
	line = input()
	items = line.replace(';', '').split(' ')
	if d.__contains__(items[1]):
		print(line.strip('\n') + ' #' + d[items[1]], end='')
	if i != m - 1:
		print()


(a, b) = [int(i) for i in input().split()]
dic1 = {}
for _ in range(a):
	(n, m) = input().split()
	dic1[m] = n
for _ in range(b):
	(c, i) = input().split()
	print(c + ' ' + i + ' #' + dic1[i[:-1]])


(n, m) = [int(i) for i in input().split()]
name_list = []
ip_list = []
for i in range(n):
	(name, ip) = input().split()
	name_list.append(name)
	ip_list.append(ip)
for i in range(m):
	line = input()
	(_, ip_match) = line.split()
	ind = ip_list.index(ip_match[:-1])
	print(line + ' #' + name_list[ind])


(n, m) = map(int, input().split())
d = {}
for _ in range(n):
	s = input().split()
	d[s[1] + ';'] = s[0]
for _ in range(m):
	s = input()
	ans = s + ' #' + d[s.split()[1]]
	print(ans)


(n, m) = [int(x) for x in input().split()]
arr = []
for _ in range(n):
	(name, ip) = input().split()
	arr.append((name, ip))
for _ in range(m):
	(name, ip) = input().split()
	ip1 = ip[:-1]
	for (i, j) in arr:
		if ip1 == j:
			print(name, ip, '#' + i)


(n, m) = map(int, input().split())
d1 = {}
for i in range(n):
	(name, ip) = map(str, input().split())
	ip += ';'
	d1[ip] = name
d2 = []
for i in range(m):
	(command, ip) = map(str, input().split())
	d2.append((command, ip))
ans = []
for (command, ip) in d2:
	name = d1[ip]
	temp = command + ' ' + ip + ' #' + name
	ans.append(temp)
print(*ans, sep='\n')


(n, m) = map(int, input().split())
d = dict([input().split()[::-1] for i in range(n)])
l = [input().split() for i in range(m)]
for i in l:
	print(i[0], i[1], '#' + d[i[1][:-1]], sep=' ')


tc = 1
while tc:
	tc -= 1
	(n, m) = map(int, input().split())
	d = {}
	for i in range(n):
		l = list(map(str, input().split()))
		d[l[1]] = l[0]
	for i in range(m):
		l = list(map(str, input().split()))
		print(l[0], l[1], '#', end='')
		print(d[l[1][:-1]])


(n, m) = list(map(int, input().split()))
name = []
ip = []
for _ in range(n):
	l = input().split()
	name.append(l[0])
	ip.append(l[1])
for _ in range(m):
	s = input().split()
	s1 = s[1][:-1]
	print(' '.join(s) + ' #{}'.format(name[ip.index(s1)]))


(n, m) = map(int, input().split())
d = {}
while n > 0:
	(name, ip) = input().split()
	d[ip + ';'] = name
	n -= 1
while m > 0:
	(name, ip) = input().split()
	print(name, ip, '#' + d[ip])
	m -= 1


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, m) = map(int, input().split(' '))
dic = {}
for x in range(n):
	(a, b) = input().split(' ')
	dic[b] = a
for y in range(m):
	(a, b) = input().split(' ')
	print(a, b, '#' + dic[b[:-1]])


(n, m) = [*map(int, input().split())]
dict1 = {}
for i in range(n):
	(value1, key1) = input().split()
	dict1[key1 + ';'] = '#' + value1
for i in range(m):
	(x, y) = input().split()
	print(x, y, dict1[y])


def main():
	(n, m) = input().split(' ')
	(n, m) = (int(n), int(m))
	d = {}
	try:
		for i in range(n):
			(name, ip) = input().split(' ')
			d[ip] = name
		for j in range(m):
			(command, ip) = input().split(' ')
			ip = ip[:len(ip) - 1]
			print('{} {}; #{}'.format(command, ip, d[ip]))
	except KeyError:
		print('key Error')
main()


(n, m) = input().split()
n = int(n)
m = int(m)
lst = []
lst2 = []
for i in range(n):
	(a, b) = input().split()
	tup = (a, b)
	lst.append(tup)
for k in range(m):
	(c, d) = input().split()
	tup = (c, d)
	lst2.append(tup)
for h in range(0, m, 1):
	for j in range(0, n, 1):
		if lst[j][1] == lst2[h][1][:-1]:
			print(lst2[h][0] + ' ' + lst2[h][1] + ' #' + lst[j][0])


import math
import sys
import re
(n, m) = map(int, input().rstrip().split())
name = []
ip = []
for x in range(n):
	s = input()
	s1 = s.split(' ')
	name.append(s1[0])
	ip.append(s1[1])
for y in range(m):
	sin = input()
	s2 = sin.split(' ')
	a = ip.index(s2[1][:-1])
	print(sin + ' #{}'.format(name[a]))


(n, m) = map(int, input().split())
table = {}
for _ in range(n):
	(name, ip) = input().split()
	table[ip] = name
for _ in range(m):
	(com, ip) = input()[:-1].split()
	print('%s %s; #%s' % (com, ip, table[ip]))


(n, m) = map(int, input().split())
d = {}
for _ in range(n):
	i = input().split()
	d[i[1]] = i[0]
for _ in range(m):
	i = input()
	print('{} #{}'.format(i, d[i.split()[1].strip(';')]))


(n, m) = map(int, input().split())
server = []
cont = []
for i in range(n):
	s = input()
	server.append(s.split())
for j in range(m):
	s = input()
	cont.append(s.split())
for i in range(m):
	st = cont[i][1]
	st = st[:len(st) - 1]
	for j in range(n):
		if server[j][1] == st:
			print(cont[i][0], cont[i][1], '#' + server[j][0])


name_ip = {}
lst = []
(n, m) = map(int, input().split())
for i in range(n):
	(name, ip) = input().split()
	ip += ';'
	name_ip[ip] = name
for j in range(m):
	(command, Cip) = input().split()
	lst.append(command + ' ' + Cip + ' #' + name_ip[Cip])
for i in lst:
	print(i)


from sys import *

def input():
	return stdin.readline().split()

def input_i():
	return map(int, input())

def input_s():
	return map(str, input())

def main():
	(n, m) = input_i()
	r = []
	t = []
	q = []
	w = []
	for i in range(n):
		(a, b) = input_s()
		r.append(a)
		t.append(b + ';')
	for i in range(m):
		(a, b) = input_s()
		q.append(a)
		w.append(b)
	for i in range(m):
		for j in range(n):
			if w[i] == t[j]:
				print(q[i] + ' ' + w[i] + ' #' + r[j])
main()


(n, m) = [int(v) for v in input().split()]
ip2name = {}
for _ in range(n):
	(name, ip) = input().split()
	ip2name[ip] = name
for _ in range(m):
	(cmd, ip) = input().split()
	assert ip[-1] == ';'
	ip = ip[:-1]
	print('%s %s; #%s' % (cmd, ip, ip2name[ip]))


(n, m) = map(int, input().strip().split(' '))
dic = {}
for i in range(n):
	(a, b) = input().split(' ')
	dic[b] = a
for i in range(m):
	(a, b) = input().split(' ')
	b = b[:-1]
	l = []
	l.append(a)
	l.append(' ')
	l.append(b)
	l.append('; #')
	l.append(dic[b])
	s = ''.join(l)
	print(s)


[n, m] = input().split()
d = {}
a = {}
for i in range(int(n)):
	text = input().split()
	d[text[1]] = text[0]
for i in range(int(m)):
	text = input().split()
	charr = text[1]
	print(text[0] + ' ' + text[1] + ' ' + '#' + d[charr[:-1]])


from collections import defaultdict
final = defaultdict(list)
(n, m) = map(int, input().split())
(d, name, ip) = ([], [], [])
for _ in range(n):
	name = []
	i = input().split()
	name.append(i[1])
	name.append(i[0])
	d.append(tuple(name))
for (k, v) in d:
	final[k].append(v)
test = []
for i in range(m):
	test = input().split()
	ans = test[1].strip(';')
	print(*test, '#', end='')
	print(*final[ans])


(n, m) = map(int, input().split())
name = []
ip = []
for i in range(n):
	(a, b) = map(str, input().split())
	name.append(a)
	ip.append(b)
for i in range(m):
	(a, b) = map(str, input().split())
	c = b[:-1]
	if c in ip:
		print(a, b, '#' + name[ip.index(c)])


(n, m) = map(int, input().split())
name = []
ip = []
for i in range(n):
	(a, b) = input().split()
	name.append(a)
	ip.append(b + ';')
for i in range(m):
	(c, d) = input().split()
	x = ip.index(d)
	print(c + ' ' + d + ' #' + name[x])


(n, m) = map(int, input().split())
(name, match) = ([], [])
for i in range(1, n + m + 1):
	s = input()
	q = s.split()
	if i <= n:
		name.append(q[0])
		name.append(q[1])
	else:
		match.append(q[0])
		match.append(q[1])
for i in range(0, len(match)):
	if (i + 1) % 2 == 0:
		k = match[i]
		h = len(k)
		st = k[0:h - 1]
		if st in name:
			ll = name.index(st)
			print(match[i - 1] + ' ' + match[i] + ' #' + name[ll - 1])


(n, m) = map(int, input().split())
a = {}
for _ in range(n):
	(x, y) = input().split()
	a[y] = x
for _ in range(m):
	(x, y) = input().split()
	print(x, y, '#' + a[y[:len(y) - 1]])


d = dict()
l = []
(n, m) = map(int, input().split())
for i in range(n):
	(name, ip) = input().split()
	d[ip] = name
for i in range(m):
	(name, ip) = input().split()
	l.append(name + ' ' + ip + ' #' + d[ip[:-1]])
for i in l:
	print(i)


s = []
t = []
inp = input().split()
n = int(inp[0])
m = int(inp[1])
for i in range(n):
	k = input()
	s.append(k)
for i in range(m):
	k = input()
	t.append(k)
for i in range(m):
	it = t[i].split(' ')[1][:-1]
	for j in range(n):
		if it == s[j].split(' ')[1]:
			t[i] = t[i] + ' ' + '#' + s[j].split(' ')[0]
for i in range(m):
	print(t[i])


from collections import OrderedDict
(n, m) = map(int, input().split())
t = n
md1 = OrderedDict()
while n:
	s = input().split()
	md1[s[1]] = s[0]
	n -= 1
while m:
	s1 = input().split()
	s3 = s1[1][:-1]
	keys = md1.keys()
	if s3 in keys:
		print(s1[0], s1[1] + ' #' + md1[s1[1][:-1]])
	m -= 1


(n, m) = map(int, input().split())
d1 = ['0'] * n
d2 = ['0'] * n
for i in range(n):
	a = input()
	fin = a.find(' ')
	d1[i] = a[:fin]
	d2[i] = a[fin + 1:]
for i in range(m):
	a = input()
	fin = a.find(' ')
	ind = d2.index(a[fin + 1:-1])
	print(a, ' #', d1[ind], sep='')


(n, m) = input().split()
(n, m) = (int(n), int(m))
d = {}
for i in range(n):
	(v, k) = input().split()
	d[k] = v
for i in range(m):
	(k, v) = input().split()
	v1 = v[:-1]
	print(k, v, '#' + d[v1])


(n, m) = list(map(int, input().split(' ')))
iptable = {}
for i in range(n):
	(a, b) = input().split(' ')
	iptable[b] = a
for i in range(m):
	(a, b) = input().split(' ')
	print(a, b, '#' + iptable[b[:-1]])


(n, m) = input().split()
n = int(n)
m = int(m)
lis1 = []
lis2 = []
lis3 = []
for i in range(n):
	a = input()
	lis1.append(a)
for i in range(m):
	b = input()
	lis2.append(b)
for j in lis2:
	for i in lis1:
		ind1 = i.index(' ')
		ind2 = j.index(' ')
		k = i[ind1 + 1:]
		l = j[ind2 + 1:-1]
		if k == l:
			print(j + ' #' + i[:ind1])


(n, m) = map(int, input().split())
d1 = {}
d2 = {}
for i in range(n):
	l1 = list(input().split())
	d1.update({l1[1]: l1[0]})
for i in range(m):
	l1 = list(input().split())
	s = l1[1]
	s1 = s[0:-1]
	print(l1[0], l1[1], '#' + d1.get(s1))


servers = {}
(n, m) = map(int, input().split())
for i in range(n):
	s = input().split()
	servers[s[1]] = s[0]
for i in range(m):
	s = input().split()
	print(*s, end=' ')
	print('#' + servers[s[1][:-1]])


(a, b) = map(int, input().split())
mapping = {}
while a:
	a -= 1
	s = list(input().split())
	mapping[s[1] + ';'] = '#' + s[0]
while b:
	b -= 1
	ss = list(input().split())
	print(' '.join(ss + [mapping[ss[1]]]))


(n, m) = [int(x) for x in input().split()]
d = {}
for _ in range(n):
	(string, ip) = input().split()
	d[ip] = string
for _ in range(m):
	(command, ip) = input().split()
	print('{} {} #{}'.format(command, ip, d[ip[:-1]]))


(n, m) = map(int, input().split())
d = {}
for _ in range(n):
	(name, ip) = input().split()
	d[ip] = name
for _ in range(m):
	s = input()
	ip = s.split()[-1]
	if ip[-1] == ';':
		ip = ip[:-1]
	print(s, '#' + d[ip])


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	(name, ip) = map(str, input().split())
	d[ip] = name
for j in range(m):
	(a, b) = map(str, input().split())
	c = b.rstrip(';')
	ans = a + ' ' + b + ' #' + d[c]
	print(ans)


(n, m) = [int(s) for s in input().split()]
a = [input().split() for i in range(n)]
for i in range(m):
	d = input().split()
	x = d[1].split(';')
	for j in range(n):
		if x[0] in a[j]:
			print(d[0] + ' ' + d[1] + ' #' + a[j][0])


(n, m) = map(int, input().split())
d = dict()
for i in range(n):
	(a, b) = map(str, input().split())
	d[b] = a
for i in range(m):
	(a, b) = map(str, input().split())
	print(a + ' ' + b + ' #' + d[b[:len(b) - 1]])


(n, m) = map(int, input().split())
a = {}
for i in range(n):
	(x, y) = input().split()
	a[y] = x
for i in range(m):
	(x, y) = input().split()
	print(x, y, '#' + a[y.replace(';', '')])


global lista

def binary_search(i, j, busco):
	while j >= i:
		m = i + (j - i) // 2
		if lista[m][0] < busco:
			i = m + 1
		elif lista[m][0] > busco:
			j = m - 1
		else:
			return lista[m][1]
(n, k) = list(map(int, input().split()))
lista = []
for x in range(0, n):
	(c1, c2) = list(map(str, input().split()))
	lista.append([c2, c1])
lista.sort()
for i in range(0, k):
	(cad1, cad2) = list(map(str, input().split()))
	cad2 = cad2[:-1]
	res = binary_search(0, n - 1, cad2)
	print(cad1, cad2 + ';', '#' + str(res))


(n, m) = [int(x) for x in input().split()]
res = []
M = []
D = []
for i in range(n):
	s = [x for x in input().split()]
	M.append(s[0])
	D.append(s[1])
for i in range(m):
	ch = [x for x in input().split()]
	res.append(' '.join(ch) + ' #' + M[D.index(ch[1].strip(';'))])
for k in res:
	print(k)


d = {}
(n, m) = map(int, input().split())
for _ in range(n):
	l = list(map(str, input().split()))
	d[l[1] + ';'] = l[0]
for _ in range(m):
	l = list(map(str, input().split()))
	print(l[0] + ' ' + l[1] + ' #' + d[l[1]])


(n, m) = [int(x) for x in input().split()]
an = []
am = []
for i in range(n):
	(a, b) = [x for x in input().split()]
	an.append(a)
	an.append(b)
for i in range(m):
	(c, d) = [x for x in input().split()]
	am.append(c)
	am.append(d)
for i in range(2 * m):
	for j in range(2 * n):
		if i % 2 == 1 and j % 2 == 1:
			temp = am[i][:len(am[i]) - 1]
			if temp == an[j]:
				print(am[i - 1] + ' ' + am[i] + ' #' + an[j - 1])


(n, m) = map(int, input().split())
nip = {}
for i in range(n):
	(name, ip) = input().strip().split()
	nip[ip] = name
for i in range(m):
	sstr = input().strip()
	(name, ip) = sstr.split()
	ip = ip[:-1]
	print(sstr + ' #' + nip[ip])


(n, m) = [int(x) for x in input().split()]
lsn = []
lsc = []
for i in range(n):
	(name, number) = input().split(' ')
	lsn.append([name, number])
for i in range(m):
	(mane, munber) = input().split(' ')
	munber = list(munber)
	munber = munber[0:len(munber) - 1]
	munber = ''.join(munber)
	lsc.append([mane, munber])
for j in range(m):
	for i in range(n):
		if lsn[i][1] == lsc[j][1]:
			print(str(lsc[j][0]) + ' ' + str(lsc[j][1]) + '; #' + str(lsn[i][0]))


servers = []
(n, m) = map(int, input().split())
for i in range(n):
	servers.append(input().split())
for i in range(m):
	s = input().split()
	print(*s, end=' ')
	for server in servers:
		if server[1] == s[1][:-1]:
			print('#', server[0], sep='')


(n, m) = map(int, input().split())
arr = dict()
for i in range(n):
	(a, b) = map(str, input().split())
	arr[b] = a
for i in range(m):
	(a, b) = map(str, input().split())
	c = b[:-1]
	print(a, b, end=' ')
	print('#', end='')
	print(arr[c])


(n, m) = map(int, input().split())
server = {}
for _ in range(n):
	(name, ip) = input().split()
	server[ip] = name
command = [x for _ in range(m) for x in input().split('\n')]
for x in command:
	(cmd, ip) = x.split()
	for key in server.keys():
		if key + ';' == ip:
			print(x, '#' + server[key])
			break


m = [int(j) for j in input().split(' ')]
a = []
b = []
for i in range(m[0]):
	a.append(input().split(' '))
for i in range(m[1]):
	b.append(input().split(' '))
for i in range(m[1]):
	for j in range(m[0]):
		if b[i][1] == a[j][1] + ';':
			print(b[i][0], b[i][1], '#' + a[j][0])
			break


(n, m) = [int(x) for x in input().split(' ')]
servers = {}
for server in range(n):
	s = input().split(' ')
	servers[s[1]] = s[0]
for command in range(m):
	c = input()
	out = c + ' #' + servers[c.split(' ')[1][:-1]]
	print(out)


(n, m) = map(int, input().split())
ips = {}
for _ in range(n):
	(name, ip) = input().split()
	ips[ip] = name
for _ in range(m):
	(name1, ip1) = input().split()
	ip1 = ip1[:-1]
	if ip1 in ips:
		print(name1, ip1 + ';', '#' + ips[ip1])


(n, m) = [int(i) for i in input().split()]
l = []
l2 = []
for i in range(n):
	l.append(input().split())
for i in range(m):
	l2.append(input().split())
for i in range(m):
	(a, b) = l2[i]
	c = b[:len(b) - 1]
	k = 0
	for j in range(n):
		if c == l[j][1]:
			k = j
			break
	print(a, b, '#' + l[k][0])


main = dict()
(n, m) = map(int, input().split())
for i in range(n):
	(name, path) = input().split()
	main[path + ';'] = name
for j in range(m):
	s = input()
	print(s, '#' + str(main[s.split()[1]]))


a = input().split()
n = int(a[0])
m = int(a[1])
b = {}
c = []
d = ''
for i in range(n):
	c = input().split()
	b[c[1]] = c[0]
for i in range(m):
	d = input()
	c = d.split()[1][:len(d.split()[1]) - 1]
	print(d + ' #' + b[c])


(n, m) = map(int, input().split())
(cmd, ip) = ([], [])
for i in range(n):
	(a, b) = map(str, input().split())
	(cmd.append(a), ip.append(b))
for i in range(m):
	(c, d) = map(str, input().split())
	print(c, d, '#' + cmd[ip.index(d[:len(d) - 1])])


import sys
(n, m) = map(int, sys.stdin.readline().split())
s = []
for i in range(n):
	(nm, ip) = input().split()
	s.append((nm, ip))
for _ in range(m):
	(nm, ip) = input().split()
	ipd = ip[:-1]
	for (i, j) in s:
		if ipd == j:
			print(nm, ip, '#' + i)


(n, m) = map(int, input().split())
f = dict()
for i in range(n):
	(s, t) = input().split()
	f[t] = s
for i in range(m):
	(s, t) = input().split()
	print(s + ' ' + t + ' #' + f[t[:-1]])


s1 = []
s2 = []
X = ''
num = input()
n = int(num.split(' ')[0])
m = int(num.split(' ')[1])
for i in range(0, n):
	x = input()
	s1.append(x)
for i in range(0, m):
	x = input()
	s2.append(x)
for j in range(0, m):
	val = s2[j]
	val = val[:-1]
	realval = val.split(' ')
	comparer1 = realval[1]
	for i in range(0, n):
		val2 = s1[i]
		realval2 = val2.split(' ')
		comparer2 = realval2[1]
		if comparer1 == comparer2:
			old = s2[j]
			old = old + ' #' + realval2[0]
			s2[j] = old
			break
for i in range(0, m):
	print(s2[i])


R = lambda : map(int, input().split())
(n, m) = R()
val_dict = {}
for _ in range(n):
	(x, y) = input().split()
	val_dict[y] = x
for i in range(m):
	val = input()
	print(val, '#' + val_dict[val.split()[1][:-1]])


(n, m) = list(map(int, input().split()))
a = []
b = []
for i in range(n):
	a.append(input().split())
for i in range(m):
	x = input().split()
	x[1] = x[1][:-1]
	b.append(x)
for i in b:
	for j in a:
		if i[1] == j[1]:
			print(*i, end='')
			print(';', end='')
			print(' #' + j[0])


(n, m) = map(int, input().split())
a = [input().split() for i in range(n)]
b = [input().split() for i in range(m)]
for i in b:
	for j in a:
		if i[1][:-1] == j[1]:
			print(i[0], i[1], '#' + j[0])


(n, m) = map(int, input().split())
d = dict((reversed(input().split()) for _ in range(n)))
for _ in range(m):
	s = input()
	print(s + ' #' + d[s.split()[1][:-1]])


import sys
import bisect as bi
import math
from collections import defaultdict as dd
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
prime1 = []

def SieveOfEratosthenes(n):
	global prime1
	prime1 = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime1[p] == True:
			for i in range(p * p, n + 1, p):
				prime1[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime1[p]:
			f.append(p)
	return f
for _ in range(1):
	(n, m) = cin()
	d = dd(list)
	d1 = dd(str)
	for i in range(n):
		s = sin().strip()
		l = list(s.split())
		add = l[-1]
		d1[add] = l[0]
	for j in range(m):
		s = sin().strip()
		l = list(s.split())
		add = l[-1][:len(l[-1]) - 1]
		print(l[0], add + ';', '#' + d1[add])


(n, m) = map(int, input().split())
h = {}
for i in range(n):
	(name, ip) = input().split()
	h[ip + ';'] = name
for j in range(m):
	(c, ip) = input().split()
	print(c, ip, '#' + h[ip])


(n, m) = map(int, input().split())
s = {}
for i in range(n):
	(a, b) = map(str, input().split())
	s[b] = a
for i in range(m):
	(a, b) = map(str, input().split())
	c = b.replace(b[-1], '')
	print(a + ' ' + b + ' ' + '#' + s.get(c))


def solve():
	for line in lines:
		ip = line[1][:-1]
		print(' '.join(line) + ' #' + d[ip])

def main():
	global n, m, d, lines
	(n, m) = list(map(int, input().split()))
	d = dict()
	for _ in range(n):
		(name, ip) = tuple(input().split())
		d[ip] = name
	lines = [input().split() for _ in range(m)]
	solve()
main()


(n, m) = map(int, input().split())
d = dict()
for i in range(n):
	s = input().split()
	d[s[1]] = s[0]
for i in range(m):
	s = input()[:-1]
	s = s.split()
	print(*s, sep=' ', end='')
	print(';', end=' ')
	print('#{}'.format(d[s[1]]))


from collections import defaultdict as dd
(n, m) = map(int, input().split())
d = {}
for i in range(0, n):
	b = input().strip()
	l = b.split()
	if l[1] not in d:
		d[l[1]] = l[0]
for i in range(0, m):
	b = input().strip()
	l = b.split(' ')
	x = len(l[1])
	a = l[1][0:x - 1]
	print(l[0], l[1], '#' + d[a])


import sys
li = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : sys.stdin.readline().strip().split()
ni = lambda : int(sys.stdin.readline().strip())
nsi = lambda : sys.stdin.readline().strip()
from collections import defaultdict as df
from math import *
(n, m) = map(int, input().split())
d = {}
for i in range(n):
	(name, ip) = input().split()
	d[ip] = name
for i in range(m):
	(a, b) = input().split()
	b = b[:-1]
	print(a, ' ' + b + '; #' + d[b])


t = input()
(n, m) = t.split()
n = int(n)
m = int(m)
track = {}
for i in range(n):
	inputs = input()
	(name, ip) = inputs.split()
	track[ip] = name
for i in range(m):
	inputs = input()
	(command, ip) = inputs.split()
	mapping = ip[0:-1]
	result = command + ' ' + ip + ' #' + track[mapping]
	print(result)


def gis():
	return list(map(int, input().strip().split()))

def gi():
	return int(input())

def gss():
	return input().strip().split()

def problem():
	(n, m) = gis()
	ip = dict()
	for i in range(n):
		(name, ips) = gss()
		ip[ips] = name
	for i in range(m):
		(command, ips) = gss()
		print(command, ips, '#{}'.format(ip[ips[:-1]]))

def __starting_point():
	problem()
__starting_point()


(n, m) = map(int, input().split())
dic = {}
for _ in range(n):
	name = input().split()
	dic[name[1]] = ' #' + name[0]
for _ in range(m):
	server = input().split()
	print(server[0], server[1], dic[server[1][:-1]])


import sys
lines = tuple((l.strip() for l in sys.stdin.readlines()))
(server_count, command_count) = (int(e) for e in lines[0].split())
servers = tuple((e for e in lines[1:server_count + 1]))
servers = dict((reversed(e.split()) for e in servers))
commands = tuple((e for e in lines[1 + server_count:]))
for command in commands:
	(_, ip) = command.split()
	ip = ip[:-1]
	server = servers[ip]
	print(command + f' #{server}')


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdarr = lambda : map(int, stdstr().split())
mod = 1000000007
(n, m) = stdarr()
names = dict()
for i in range(n):
	s = input().split()
	names[s[1]] = s[0]
command = dict()
for _ in range(m):
	s = input().split()
	print(s[0] + ' ' + s[1][:-1] + '; #' + names[s[1][:-1]])


(n, m) = [int(x) for x in input().split()]
s = []
s1 = []
x = []
y = []
x1 = []
y1 = []
for i in range(n):
	s.append([str(x) for x in input().split()])
for i in range(n):
	y1.append(s[i][0])
	b = list(s[i][1])
	y.append(b)
for i in range(m):
	s1.append([str(x) for x in input().split()])
for i in range(m):
	x1.append(s1[i][0])
	a = list(s1[i][1])
	x.append(a[:-1])
for i in range(m):
	for j in range(n):
		if x[i] == y[j]:
			print(x1[i], end=' ')
			print(''.join(x[i]), end='')
			print(';', end=' ')
			print('#', end='')
			print(y1[j])
			continue


n = input().split()
m = int(n[1])
n = int(n[0])
a = []
b = []
for i in range(n):
	k = input().split()
	h = k[1].split('.')
	k = k[0]
	a.append(k)
	b.append(h)
for i in range(m):
	k = input().split()
	hh = k[1][:-1]
	h = hh.split('.')
	k = k[0]
	for j in range(n):
		if b[j] == h:
			hh = hh + ';'
			a[j] = '#' + a[j]
			print(k, hh, a[j])
			hh = hh[:-1]
			a[j] = a[j][1:]


a = input()
(n, m) = a.split()
n = int(n)
m = int(m)
l = dict()
for i in range(n):
	string = input()
	s = string.split()
	l[s[1]] = s[0]
for i in range(m):
	string = input()
	s = string.split()
	print(s[0] + ' ' + s[1][0:-1] + '; #' + l[s[1][0:-1]])


n = list(map(int, input().split()))
lst = []
for i in range(n[0]):
	n1 = input().split()
	lst.append(n1)
for j in range(n[1]):
	n2 = input().split()
	for k in lst:
		s = str(n2[1])
		w = s[:-1]
		if w == k[1]:
			print(n2[0], n2[1], '#' + k[0])


(n, m) = map(int, input().split())
names = {}
for i in range(n):
	(name, ip) = input().split()
	names[ip] = name
for j in range(m):
	(op, ip) = input().split()
	print(op, ip, '#' + names[ip[:-1]])


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l += input().split()
for i in range(m):
	(a, b) = input().split()
	c = list(b)
	c.remove(c[-1])
	c = ''.join(c)
	print(a + ' ' + b + ' #' + l[l.index(c) - 1])


nn = input()
nn = nn.split()
n = int(nn[0])
m = int(nn[1])
di = dict()
for i in range(n):
	k = input()
	k = k.split()
	mm = k[0]
	l = k[1]
	kk = l + ';'
	di[kk] = mm
for i in range(m):
	j = input()
	j = j.split()
	jj = j[0]
	h = j[1]
	print(jj, h, '#' + str(di[h]))


(n, m) = list(map(int, input().split()))
s = {}
for i in range(n):
	t = input().split()
	s.update({t[1]: t[0]})
ans = []
for i in range(m):
	t = input()[:-1].split()
	ans.append(' '.join(t) + '; #' + s[t[1]])
for i in ans:
	print(i)


(a, b) = map(int, input().split())
names = dict()
for i in range(a):
	(x, y) = input().split()
	names[y] = x
for i in range(b):
	com = input()
	h = com.split()[-1][:-1]
	print(f'{com} #{names[h]}')


(n, m) = list(map(int, input().split(' ')))
d = {}
for _ in range(n):
	entries = input().split(' ')
	name = entries[0]
	ip = entries[1]
	d[ip] = name
rets = []
for _ in range(m):
	entries = input().split(' ')
	command = entries[0]
	ip = entries[1][:-1]
	rets.append('%s %s; #%s' % (command, ip, d[ip]))
for ret in rets:
	print(ret)


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	(im, num) = input().split()
	d[num] = im
res = []
for j in range(m):
	(im, num) = input().split()
	res.append(im + ' ' + num + ' #' + d[num[:-1]])
for i in res:
	print(i)


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	(name, ip) = input().split()
	d[ip + ';'] = name
for i in range(m):
	(command, ip) = input().split()
	print('{} {} #{}'.format(command, ip, d[ip]))


i = input
(n, m) = map(int, i().split())
d = dict([i().split()[::-1] for _ in [0] * n])
for _ in [0] * m:
	a = i()
	print(a, '#' + d[a.split()[1][:-1]])


(n, m) = list(map(int, input().strip().split(' ')))
ips = {}
for _ in range(n):
	(name, ip) = input().strip().split(' ')
	ips[ip] = name
for _ in range(m):
	line = input().strip().split(' ')
	line[1] = line[1] + ' ' + '#' + ips[line[1][:-1]]
	print(' '.join(line))


(n, m) = map(int, input().split())
d = dict()
for i in range(n):
	cur = list(map(str, input().split()))
	d[cur[1]] = cur[0]
for i in range(m):
	s = input()
	cur = s[:-1].split()
	print(s, '#' + d[cur[1]])


line1 = str(input())
line1 = line1.split()
n = int(line1[0])
m = int(line1[1])
d = {}
for i in range(n):
	line = str(input())
	line = line.split(' ')
	d[line[1]] = line[0]
for i in range(m):
	line_str = str(input())
	line_list = line_str.split(' ')
	print(line_str + ' #%s' % d[line_list[1].rstrip(';')])


(n, m) = map(int, input().split())
l = [[i for i in input().split()] for i in range(n + m)]
for i in range(m):
	print(' '.join(l[i + n]), end='')
	for j in range(n):
		if l[i + n][1][:-1] in l[j]:
			s = l[j][0]
	print(' #', s, sep='')


(n, m) = [int(x) for x in input().split()]
l1 = []
l2 = []
for i in range(1, n + 1):
	(a, b) = input().split()
	l1.append(a)
	l2.append(b)
for i in range(1, m + 1):
	(a, b) = input().split()
	ind = l2.index(b[0:len(b) - 1])
	ch = '#' + l1[ind]
	print(a, b, ch, end=' ')
	print()


(n, m) = map(int, input().split())
server = dict()
for _ in range(n):
	(name, ip) = input().split()
	server[ip + ';'] = '#' + name
for _ in range(m):
	(command, ip) = input().split()
	print(command, ip, server[ip])


a = [int(q) for q in input().strip().split()]
b = {}
for k in range(a[0]):
	d = input().split()
	b[d[1]] = d[0]
for k in range(a[1]):
	d = input().split()
	for p in b:
		if p + ';' == d[1]:
			print(d[0] + ' ' + d[1] + ' #' + b[p])
			break


import math
import sys
input = sys.stdin.readline

def invr():
	return list(map(int, input().split()))

def inlt():
	return list(map(str, input().split()))
(n, m) = invr()
servers = {}
commands = {}
for i in range(n):
	e = inlt()
	servers[e[1]] = '#' + e[0]
for i in range(m):
	e = inlt()
	ee = e[1].replace(';', '')
	print(e[0], e[1], servers[ee])


(n, m) = list(map(int, input().split()))
sern = []
ips = []
for k in range(n):
	t = list(input().split())
	sern.append(t[0])
	ips.append(t[1] + ';')
for w in range(m):
	e = input()
	u = list(e.split())
	print(e + ' #' + sern[ips.index(u[1])])


(n, m) = [int(x) for x in input().split()]
name = {}
for i in range(n):
	x = input().split()
	name[x[1]] = x[0]
for i in range(m):
	x = input().split()
	t = x[1].split(';')
	print(x[0], x[1], '#' + name[t[0]])


def find(s, ip):
	for i in range(len(ip)):
		if ip[i] == s:
			return i
	return -1
(n, m) = map(int, input().split())
(ip, ip_dict) = ([], [])
for i in range(n):
	s1 = input().split()
	ip.append(s1[1])
	ip_dict.append(s1[0])
for i in range(m):
	s1 = input()
	s2 = s1.split()[1]
	m = find(s2[:len(s2) - 1], ip)
	print(s1, end='')
	print(' #', end='')
	print(ip_dict[m])


d = {}
L = list(map(int, input().split()))
N = L[0]
M = L[1]
for i in range(N):
	(v, c) = input().split()
	c += ';'
	d[c] = v
for j in range(M):
	(f, b) = input().split()
	K = '#' + d[b]
	print(f, b, K)


import string
stdin = input()
n = stdin.split()[0]
n = int(n)
m = int(stdin.split()[1])
dict = {}
for i in range(n):
	stdin = input()
	name = stdin.split()[1]
	dict[name] = stdin.split()[0]
for i in range(m):
	stdin = input()
	name = dict[stdin.split()[1].rstrip(';')]
	print(stdin + ' #' + name)


(n, m) = [int(i) for i in input().split()]
a = []
b = []
c = []
d = []
for i in range(n):
	x = input()
	a.append(x)
for i in a:
	x = i.split(' ')
	b.append(x)
for i in range(m):
	x = input()
	s = x.split(' ')
	for i in b:
		if i[1] == s[1][:-1]:
			print(x, '#' + i[0])


n = [int(x) for x in input().strip().split()]
m = n[1]
n = n[0]
x = {}
for i in range(n):
	a = input().split()
	x[a[1]] = a[0]
for i in range(m):
	a = input().strip()
	y = a.split()[1][:-1]
	print(a, str('#' + x[y]))


TN = 1

def solution():
	(n, m) = map(int, input().split())
	names = []
	ips = []
	for i in range(n):
		(n, ip) = input().split()
		names.append(n)
		ips.append(ip)
	opers = []
	ip_s = []
	for i in range(m):
		(o, ip) = input().split()
		opers.append(o)
		ip_s.append(ip)
	for i in range(m):
		ind = ips.index(ip_s[i][:-1])
		print(str(opers[i]) + ' ' + str(ip_s[i]) + ' #' + str(names[ind]))
while TN != 0:
	solution()
	TN -= 1


def main():
	[n, m] = [int(_) for _ in input().split()]
	servers = {}
	for _ in range(n):
		[name, ip] = input().split()
		servers[ip] = name
	for _ in range(m):
		command = input()
		ip = command.split()[1]
		ip = ip[:len(ip) - 1]
		command += ' #%s' % servers[ip]
		print(command)
main()


l = dict()
for _ in ' ' * sum(map(int, input().split())):
	(z, x) = map(str, input().split())
	x = x.rstrip(';')
	if x not in l:
		l[x] = z
	else:
		print(z + ' ' + x + '; #' + l.get(x))


(n, m) = input().split()
n = int(n)
m = int(m)
name_ip = {}
comm_ip = []
for i in range(0, n):
	(name, ip) = input().split()
	ip += ';'
	name_ip[ip] = name
for i in range(0, m):
	(comm, ip) = input().split()
	comm_ip += [(comm, ip)]
for (comm, ip) in comm_ip:
	answer = comm + ' ' + ip + ' #' + name_ip[ip]
	print(answer)


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	temp = input().split()
	d[temp[1]] = temp[0]
for i in range(m):
	temp = input()
	data = temp.split()
	print(temp, end=' ')
	print('#' + d[data[1][:-1]])


(n, m) = map(int, input().split(' '))
servs = {}
for i in range(0, n):
	(name, ip) = input().split(' ')
	servs[ip] = name
for j in range(0, m):
	(command, ip) = input().split(' ')
	print('{} {} #{}'.format(command, ip, servs[ip[:-1]]))


(n_names, n_commands) = map(int, input().strip().split())
d = {}
for i in range(n_names):
	(name, sid) = input().strip().split()
	d[sid] = name
for j in range(n_commands):
	c = input().strip()
	(_, cid) = c.split()
	cid = cid[:-1]
	print(c + ' #' + d[cid])


(_1, _2) = map(int, input().split())
(name, ip) = ([], [])
for i in range(_1):
	(x, y) = ('', '')
	(x, y) = map(str, input().split())
	name.append(x)
	ip.append(y)
(names, ips) = ([], [])
for i in range(_2):
	(x, y) = ('', '')
	(x, y) = map(str, input().split())
	names.append(x)
	ips.append(y)
for i in range(len(names)):
	print(names[i] + ' ' + ips[i], end=' ')
	a = 0
	while 1:
		if ips[i] == ip[a] + ';':
			print('#' + name[a])
			break
		else:
			a += 1


x = input()
x = x.strip().split(' ')
n = int(x[0])
m = int(x[1])
name = []
name2 = []
ip = []
ip2 = []
for i in range(n):
	temp = input()
	temp = temp.strip().split(' ')
	name.append(temp[0])
	temp[1] += ';'
	ip.append(temp[1])
for i in range(m):
	temp = input()
	temp = temp.strip().split(' ')
	name2.append(temp[0])
	ip2.append(temp[1])
for i in range(m):
	print('%s %s ' % (name2[i], ip2[i]), end='')
	for j in range(n):
		if ip2[i] == ip[j]:
			print('#%s' % name[j])
			break


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	(str1, str2) = input().split()
	d[str2 + ';'] = str1
for i in range(m):
	(str1, str2) = input().split()
	print(str1 + ' ' + str2 + ' #' + d[str2])


(n, m) = map(int, input().split())
name = []
ip = []
for i in range(n):
	(a, b) = input().split()
	name.append(a)
	ip.append(b)
for i in range(m):
	l = list(input().split())
	ind = ip.index(l[1][0:len(l[1]) - 1])
	str = '#'
	str += name[ind]
	l.append(str)
	for j in l:
		print(j, end=' ')
	print()


(n, m) = map(int, input().split())
name = [''] * n
ip = [''] * n
for i in range(n):
	inp = input()
	name[i] = str(inp.split()[0])
	ip[i] = str(inp.split()[1])
for i in range(m):
	inp = input().strip(';')
	nm = str(inp.split()[0])
	i = str(inp.split()[1])
	print(nm + ' ' + i + '; #' + name[ip.index(i)])


(m, n) = map(int, input().split())
s1 = dict((reversed(input().split()) for _ in range(m)))
for _ in range(n):
	l = input()
	(c, d) = l.split()
	print(l + ' #' + s1[d[:-1]])


(n, m) = [int(i) for i in input().split()]
d = {}
for j in range(n):
	(name, ip) = [i for i in input().split()]
	d[ip] = name
for j in range(m):
	(st, ip) = [i for i in input().split()]
	print(st + ' ' + ip + ' #' + d[ip[:-1]])


import re
ab = input().split()
a = int(ab[0])
b = int(ab[1])
comment = []
command = []
for i in range(a):
	comment.append(str(input()).replace(' ', '-'))
for i in range(b):
	command.append(str(input()).replace(' ', '-'))
ans = ''
for i in command:
	y = i.split('-')[1]
	y = y[:-1]
	for j in comment:
		x = j.split('-')[1]
		if x == y:
			ans = ans + '\n' + str(i).replace('-', ' ') + ' #' + str(j.split('-')[0])
print(ans.strip())


s = input()
s = s.split()
n = int(s[0])
m = int(s[1])
a = []
b = []
for i in range(n):
	s = input()
	a.append(s)
for i in range(m):
	s = input()
	b.append(s)
result = []
for i in b:
	for j in a:
		if i[i.index(' ') + 1:-1] in j:
			c = i + ' #' + j[:j.index(' ')]
			result.append(c)
for i in result:
	print(i)


from operator import itemgetter
(n, m) = map(int, input().split())
servers = {}
for i in range(n):
	(name, server) = input().split()
	servers[server] = name
for i in range(m):
	s = input()
	(name, server) = s.split()
	server = server[:-1]
	print(s, '#' + servers[server])


(n, m) = map(int, input().split())
name = {}
for i in range(n):
	arr = input().split()
	name[arr[1]] = arr[0]
for i in range(m):
	s = input()
	s = s[:-1]
	s = s.split()
	print(' '.join(s), '; #', name[s[1]], sep='')


from pprint import pprint as pp

def GI():
	return int(input())

def GIS():
	return list(map(int, input().split()))

def main():
	(n, m) = GIS()
	d = {}
	for i in range(n):
		(name, ip) = input().split()
		d[ip] = name
	for i in range(m):
		s = input()
		ip = s.split()[1][:-1]
		print('%s #%s' % (s, d[ip]))
main()


(n, k) = list(map(int, input().split()))
d = {}
for i in range(n):
	(site, ip) = input().split()
	d[ip] = site
for i in range(k):
	s = input()
	ip = s.split()[1][:-1]
	print(s, end='')
	print(' #' + d[ip])


(n, m) = map(int, input().split())
l = []
for i in range(n):
	k = input().split()
	l.append((k[1] + ';', k[0]))
for i in range(m):
	h1 = input()
	h = h1.split()
	k = ['#' + l[i][1] for i in range(n) if h[1] == l[i][0]]
	print(*h + k)


(n, m) = [int(x) for x in input().split(' ')]
name = []
ip = []
for i in range(n):
	s = input().split(' ')
	name.append(s[0])
	ip.append(s[1])
for a in range(m):
	command = input().split(' ')
	ind_ip = ip.index(command[1][:-1])
	command.append('#' + name[ind_ip])
	print(' '.join(command))


(n, m) = input().split()
n = int(n)
m = int(m)
names = dict()
commands = [0] * m
for i in range(n):
	(name, ip) = input().split()
	names[ip] = name
for i in range(m):
	commands[i] = input()
for command in commands:
	(cmd, ip) = command.strip(';').split()
	print(cmd + ' ' + ip + '; #' + names[ip])


(n, m) = map(int, input().split())
d = {}
for _ in range(n):
	(a, b) = input().split()
	d[b] = a
for _ in range(m):
	(a, b) = input().split()
	print('{} {} #{}'.format(a, b, d[b[:-1]]))


(n, m) = input().split()
(n, m) = (int(n), int(m))
dict = {}
for i in range(n):
	(name, ip) = input().split()
	dict[ip] = name
for i in range(m):
	(command, ip) = input().split()
	ip = ip[:-1]
	name = dict[ip]
	print('{} {}; #{}'.format(command, ip, name))


(n, m) = map(int, input().split())
di = {}
for i in range(n):
	(com, ip) = input().split()
	di[ip] = com
for i in range(m):
	(com, ip) = input().split()
	print(com + ' ' + ip + ' #{}'.format(di[ip[:-1]]))


(n, m) = map(int, input().split())
us = {}
for i in range(n):
	(name, ip) = input().split()
	us[ip] = name
for j in range(m):
	(uname, ip) = input().split()
	ip = ip[:len(ip) - 1]
	print(uname, ip + '; #' + us[ip])


(n, m) = map(int, input().split())
s = {}
for i in range(n):
	(name, ip) = map(str, input().split())
	s[ip] = name
for j in range(m):
	tmp = input()
	print(tmp + ' #' + s[tmp[tmp.index(' ') + 1:-1]])


(a, b) = [int(x) for x in input().split()]
name_dict = {}
for i in range(a):
	(c, d) = input().split()
	name_dict[d] = c
for i in range(b):
	(e, f) = input().split()
	print('%s %s #%s' % (e, f, name_dict[f[:-1]]))
	name_dict[f[:-1]]


import sys
inf = [int(x) for x in sys.stdin.readline().split(' ')]
ser = {}
for i in range(inf[0]):
	new = sys.stdin.readline().split(' ')
	ser[new[1].strip() + ';'] = new[0].strip()
for i in range(inf[1]):
	new = sys.stdin.readline()
	print(new.strip() + ' #' + ser[new.split(' ')[1].strip()])
sys.exit()


(n, m) = [int(i) for i in input().split()]
ips = dict()
for i in range(n):
	(name, ip) = input().split()
	ips[ip + ';'] = name
for i in range(m):
	inp = input().split()
	print(' '.join(inp) + ' #%s' % ips[inp[1]])


(n, m) = input().split()
n = int(n)
m = int(m)
names = {}
for i in range(n):
	str = input().split()
	names[str[1]] = str[0]
for i in range(m):
	str = input().split()
	str.append(names[str[1][:-1]])
	print('%s %s #%s' % (str[0], str[1], str[2]))


(n, m) = list(map(int, input().split()))
d = {}
for i in range(n):
	(name, ip) = input().split()
	d[ip] = name
for i in range(m):
	(cmd, ip) = input().split()
	print(cmd, ip, '#' + d[ip.strip(';')])


names = []
names_2 = []
ips = []
(n, m) = list(map(int, input().split()))
for i in range(n):
	(name, ip) = input().split()
	names += [name]
	ips += [ip]
commands_ips = []
for i in range(m):
	(command_ip, name) = input().split(';')
	commands_ips += [command_ip]
	names_2 += name
for i in range(m):
	print(commands_ips[i] + '; #' + names[ips.index(commands_ips[i].split()[1])])


(n, m) = map(int, input().strip().split(' '))
ser = {}
for i in range(n):
	(a, b) = input().strip().split(' ')
	ser[b] = a
out = ''
for i in range(m):
	(a, b) = input().strip().split(' ')
	out += a + ' ' + b + ' #' + ser[b[:len(b) - 1]] + '\n'
print(out)


def main():
	(n, m) = map(int, input().split())
	nms = {}
	for i in range(n):
		(nm, ip) = input().split()
		nms[ip] = nm
	for j in range(m):
		(nm, ip) = input().split()
		print('%s %s #%s' % (nm, ip, nms[ip[:-1]]))

def __starting_point():
	main()
__starting_point()


n = input().split()
a = int(n[0])
b = int(n[1])
li1 = []
li2 = []
for i in range(a):
	c = input().split()
	li1.append(c[0])
	c[1] = c[1] + ';'
	li2.append(c[1])
li3 = []
li4 = []
for i in range(b):
	d = input().split()
	li3.append(d[0])
	li4.append(d[1])
for i in range(b):
	for j in range(a):
		n = str(li4[i])
		m = str(li2[j])
		if n == m:
			x = li3[i] + ' ' + li4[i] + ' #' + li1[j]
			print(x)


(n, m) = map(int, input().split())
server = {}
for i in range(n):
	(name, ip) = input().split()
	server[ip] = name
for i in range(m):
	(command, ip) = input().split()
	ip = ip[:-1]
	print('%s %s; #%s' % (command, ip, server[ip]))


lst = list(map(int, input().split()))
m = lst[0]
n = lst[1]
table = list()
for i in range(0, m):
	lst = list(map(str, input().split()))
	table.append(lst)
for i in range(0, n):
	lstt = list(map(str, input().split()))
	for j in range(0, m):
		if lstt[1] == table[j][1] + ';':
			print(lstt[0] + ' ' + lstt[1], end=' #')
			print(table[j][0])
			break


(n, m) = map(int, input().split())
l = []
for i in range(n + m):
	s = list(map(str, input().split()))
	l.append(s)
for i in range(n, m + n):
	for j in range(n):
		if l[i][1] == l[j][1] + ';':
			print(l[i][0] + ' ' + l[i][1] + ' #' + l[j][0])


(n, m) = map(int, input().split(' '))
a = []
b = []
c = []
d = []
e = []
v = 0
for i in range(n):
	a.append(input())
	for j in range(len(a[i])):
		if a[i][j] == ' ':
			k = j
			break
	c.append(a[i][0:k])
	a[i] = a[i][k + 1:]
for i in range(m):
	b.append(input())
	for j in range(len(b[i])):
		if b[i][j] == ' ':
			p = j
			break
	d.append(b[i][p + 1:len(b[i]) - 1])
for i in range(m):
	for j in range(n):
		if d[i] == a[j]:
			b[i] = b[i] + ' #' + c[j]
			v = 1
			break
for i in range(m):
	print(b[i])


(n, m) = map(int, input().split())
nam = []
ip = []
for q in range(n):
	(a, b) = input().split()
	nam.append(a)
	ip.append(b)
for f in range(m):
	(c, d) = input().split()
	u = ip.index(d[:len(d) - 1])
	print(c, d, end=' ')
	print('#' + nam[u])


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	(name, ip) = input().split()
	d[ip] = name
for i in range(m):
	(name, ip) = input()[:-1].split()
	print(f'{name} {ip}; #{d[ip]}')


(n, m) = list(map(int, input().split()))
d = {}
for i in range(n):
	(name, ip) = input().split()
	d[ip] = name
for i in range(m):
	(comm, ip) = input().split()
	name = d[ip[:-1]]
	print(comm + ' ' + ip + ' #' + name)


(z, x) = map(int, input().split())
d = {}
for i in range(z):
	(a, b) = map(str, input().split())
	d[b] = a
for i in range(x):
	(c, v) = map(str, input().split())
	y = v[:len(v) - 1]
	if y in d:
		print(c, v, '#' + d[y])


(n, m) = list(map(int, input().split()))
ips = dict()
for _ in range(n):
	s = input().strip().split()
	ips[s[1]] = s[0]
for _ in range(m):
	s = input().strip().split()
	s[1] = s[1][:-1]
	print(s[0], s[1] + ';', '#' + ips[s[1]])


R = lambda t: tuple(map(t, input().split()))
rn = lambda : R(int)
(n, m) = rn()
g = {}
for i in range(n):
	(a, b) = input().split()
	b = tuple(map(int, b.split('.')))
	g[b] = a
for i in range(m):
	s = input()
	(a, b) = s[:-1].split()
	b = tuple(map(int, b.split('.')))
	print(s + ' #' + g[b])


[n, m] = [int(x) for x in input().split()]
nd = {}
for i in range(n):
	a = input().split()
	nd[a[1]] = a[0]
for i in range(m):
	a = input().split()
	print(' '.join(a) + ' #' + nd[''.join(list(a[1])[:-1])])


a = list(map(int, input().split()))
(n, m) = (a[0], a[1])
dict = {}
for i in range(n):
	x = list(input().split())
	dict[x[1]] = x[0]
for i in range(m):
	y = list(input().split())
	print(y[0] + ' ' + y[1] + ' #' + dict[y[1][0:-1]])


(n, m) = list(map(int, input().strip().split()))
host = dict()
guest = dict()
for i in range(n):
	(name, ip) = input().strip().split()
	host[ip] = name
for i in range(m):
	(name, ip) = input().strip().split()
	newline = '#' + host[ip[:-1]]
	print(name, ip, newline)


(N, M) = map(int, input().split())
nameserver = {}
while N > 0:
	N -= 1
	(a, b) = input().split()
	nameserver[b] = a
while M > 0:
	M -= 1
	(a, b) = input().split()
	print(a + ' ' + b + ' ' + '#' + nameserver[b[:-1]])


l1 = [int(x) for x in input().split()]
(n, m) = (l1[0], l1[1])
addresses = []
names = []
for x in range(n + m):
	s = input()
	l2 = s.split()
	name = l2[0]
	address = l2[1]
	address1 = l2[1]
	if ';' in address1:
		print(s + ' ' + '#' + names[addresses.index(address)])
	else:
		addresses.append(address1 + ';')
		names.append(name)


(n, m) = map(int, input().strip().split())
l = {}
for _ in range(n):
	(n, ip) = input().strip().split()
	l[ip] = n
for _ in range(m):
	line = input().strip()
	(c, ip) = line.split()
	ip = ip[:-1]
	print('{} {}; #{}'.format(c, ip, l[ip]))


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	(name, ip) = input().split()
	d[ip] = name
for i in range(m):
	(command, ip) = input().split()
	print(command + ' ' + ip + ' #' + d[ip[:len(ip) - 1]])


(n, m) = [int(i) for i in input().split()]
a = []
for i in range(n):
	b = input().split()
	a.append(b)
for i in range(m):
	p = input()
	z = p.split()
	z[1] = z[1].replace(';', '')
	for j in range(n):
		if z[1] == a[j][1]:
			print(p + ' #' + a[j][0])


(n, m) = map(int, input().split())
h = {}
for i in range(n):
	a = input()
	(name, ip) = a.split()
	h[ip] = name
for i in range(m):
	a = input()
	(name, ip) = a.split()
	s = ip.replace(';', '')
	s1 = '#' + h[s]
	print(a, s1)


(n, m) = map(int, input().split())
(alfa, betta) = ([], [])
for i in range(n):
	(x, y) = map(str, input().split())
	x = '#' + x
	alfa.append(x)
	betta.append(y)
for j in range(m):
	(x1, y1) = map(str, input().split())
	for j in range(n):
		if y1[0:len(y1) - 1] == betta[j]:
			print(x1, y1, alfa[j])


(n, m) = map(int, input().split())
name = []
ip = []
for i in range(n):
	(a, b) = input().split()
	b = b + ';'
	name.append(a)
	ip.append(b)
for i in range(m):
	(a, b) = input().split()
	k = ip.index(b)
	print(a, b, '#' + name[k])


(n, m) = map(int, input().split())
dic = {}
for i in range(n):
	(name, ip) = input().split()
	dic[ip] = name
for i in range(m):
	(comm, ip) = input().split()
	ip = ip[:len(ip) - 1]
	print(comm, ip + ';', '#' + dic[ip])


(n, m) = map(int, input().split())
a = []
b = []
for i in range(n):
	(x, y) = input().split()
	y = y + ';'
	a.append(x)
	a.append(y)
for i in range(m):
	(x, y) = input().split()
	b.append(x)
	b.append(y)
for i in range(len(b)):
	if i % 2 == 0:
		print(b[i], end=' ')
	else:
		for j in range(len(a)):
			if b[i] == a[j]:
				print(b[i] + ' #' + a[j - 1])


(nstr, mstr) = input().split(' ')
n = int(nstr)
m = int(mstr)
servers = {}
for i in range(n):
	(name, ip) = input().split(' ')
	servers[ip + ';'] = name
for i in range(m):
	(cmd, ip) = input().split(' ')
	print(cmd, ip, '#' + servers[ip])


(n, m) = list(map(int, input().split()))
D = {}
for _ in range(n):
	(name, ip) = input().split()
	D[ip] = name
for _ in range(m):
	s = input()
	ip = s.split()[1][:-1]
	s += ' #' + D[ip]
	print(s)


amount = input().split()
list_of_info = []
list_of_event = []
for i in range(int(amount[0])):
	info = input().split()
	list_of_info.append(info)
for j in range(int(amount[1])):
	event = input().split()
	list_of_event.append(event)
for i in list_of_event:
	for j in list_of_info:
		if i[1][:-1] == j[1]:
			print(i[0] + ' ' + i[1] + ' #' + j[0])


(n, m) = map(int, input().split())
a = []
ipa = []
b = []
ipb = []
for i in range(n):
	(y, x) = map(str, input().split())
	a.append(y)
	ipa.append(x)
for i in range(m):
	(y, x) = map(str, input().split())
	for j in range(n):
		if x[:len(x) - 1] == ipa[j]:
			print(y + ' ' + x + ' #' + a[j])


(n, m) = [int(i) for i in input().split()]
s = [0] * n
for i in range(n):
	s[i] = input().split()
for i in range(m):
	temp = input().split()
	for j in range(n):
		if temp[1][0:-1] in s[j]:
			print(temp[0] + ' ' + temp[1] + ' #' + s[j][0])
			break


(n, m) = map(int, input().split())
sip = []
sname = []
for i in range(n):
	q = input().split()
	sip.append(q[1])
	sname.append(q[0])
for i in range(m):
	s = input().split()
	s[1] = s[1][:len(s[1]) - 1]
	for j in range(n):
		if sip[j] == s[1]:
			print(s[0] + ' ' + s[1] + '; #' + sname[j])
			break


(n, m) = map(int, input().split())
names = [tuple(input().split()[::-1]) for i in range(n)]
names = dict(names)
for i in range(m):
	s = input()
	s += ' #' + names[s.split()[-1][:-1]]
	print(s)


x = [int(i) for i in input().split()]
(n, m) = (x[0], x[1])
d = {}
for i in range(n):
	x = input().split()
	(name, ip) = (x[0], x[1])
	if name not in d:
		d[ip] = name
for i in range(m):
	x = input().split()
	s = x[1].replace(';', '')
	print(x[0], ' ', x[1], ' #', d[s], sep='')


def read_line():
	line = input()
	return tuple(line.split(' '))
(n, m) = read_line()
n = int(n)
m = int(m)
ipdict = {}
for i in range(n):
	(dom, ip) = read_line()
	ipdict[ip] = dom
res = ''
for i in range(m):
	line = input()
	(_, ip) = line.split(' ')
	res += line + ' #' + ipdict[ip[:-1]] + '\n'
print(res)


(n, m) = [int(i) for i in input().split()]
a = []
b = []
s = ''
for i in range(n):
	(name, ip) = [j for j in input().split()]
	a.append((name, ip))
for i in range(m):
	(command, ip) = [j for j in input().split()]
	b.append((command, ip[0:-1]))
for i in range(m):
	for j in range(n):
		if b[i][1] == a[j][1]:
			print(b[i][0], b[i][1] + ';', '#' + a[j][0])


nm = input().split()
n = int(nm[0])
m = int(nm[1])
dict = {}
for i in range(0, n):
	kv = input().split()
	dict[kv[1] + ';'] = kv[0]
for j in range(0, m):
	command = input().split()
	s = command[0] + ' ' + command[1] + ' ' + '#' + dict[command[1]]
	print(s)


(n, m) = list(map(int, input().split()))
server = {}
for i in range(n):
	(name, ip) = input().split()
	server[ip] = name
for i in range(m):
	(cmd, ip) = input().split()
	print('%s %s #%s' % (cmd, ip, server[ip[:-1]]))


(n, m) = map(int, input().split())
x = {}
for i in range(n):
	(a, b) = input().split()
	x[b] = a
for i in range(m):
	(a, b) = input().split()
	print(a, b, '#' + x[b[:-1]])


(n, m) = map(int, input().split())
s = dict()
for x in range(n):
	(name, ip) = input().split()
	s[ip] = name
for y in range(m):
	(a, b) = input().split()
	c = b[:-1]
	print(a, b, '#' + s[c])


(n, m) = list(map(int, input().split()))
a = {}
for i in range(n):
	(x, y) = input().split()
	a[y] = x
for i in range(m):
	s = input()
	print(s, '#' + a[s.split()[1][:-1]])


(n, m) = map(int, input().split())
myList = []
myFinalList = []
for i in range(0, n):
	(name, ip) = map(str, input().split())
	myUnit = [name, ip]
	myList.append(myUnit)
for j in range(0, m):
	(name1, ip1) = map(str, input().split())
	x = len(ip1) - 1
	myUnit1 = [name1, ip1[:x]]
	sensor = 0
	counter = 0
	while sensor == 0:
		if myUnit1[1] != myList[counter][1]:
			counter += 1
		else:
			sensor = 1
			myList2 = ['#', myList[counter][0]]
			myList2 = ''.join(myList2)
			myList3 = [myUnit1[1], ';']
			myList3 = ''.join(myList3)
			myUnit1.pop()
			myUnit1.append(myList3)
			myUnit1.append(myList2)
			myFinalList.append(myUnit1)
for y in range(0, len(myFinalList)):
	print(*myFinalList[y])


f = lambda : map(int, input().split())
(n, m) = f()
d = dict()
while n:
	(a, b) = input().split()
	d[b] = a
	n -= 1
while m:
	(a, b) = input().split()
	b = b.replace(b[-1], '')
	print(a, b + ';', '#' + d[b])
	m -= 1


l = [int(x) for x in input().split()]
l1 = []
for i in range(l[0] + l[1]):
	l1.append([x for x in input().split()])
for i in range(l[0], l[0] + l[1]):
	for j in range(0, l[0]):
		if l1[i][1][0:-1] == l1[j][1]:
			print(l1[i][0] + ' ' + l1[i][1] + ' #' + l1[j][0])


R = lambda type_='int': list(map(eval(type_), input().split(' ')))
(n, m) = R()
d = dict()
for i in range(n):
	(a, b) = R('str')
	d[b] = a
for i in range(m):
	(a, b) = R('str')
	print(a + ' ' + b + ' ' + '#' + d[b[:-1]])


i = input()
(n, m) = i.split(' ')
n = int(n)
m = int(m)
sets = set()
for i in range(0, n):
	set = input()
	sets.add(set)
for i in range(0, m):
	set = input()
	(n, ip1) = set.split(' ')
	for j in sets:
		(name, ip) = j.split(' ')
		new = ip1.replace(';', '')
		if new == ip:
			name = '#' + name
			print(set, name)
			break


(var1, var2) = input().split()
listname = []
listcommand = []
listsorite = []
for i in range(int(var1)):
	nameip = input()
	listname.append(nameip)
for j in range(int(var2)):
	commandip = input()
	listcommand.append(commandip)
	listcommandsplit = commandip.split(' ')
	listcommandsplit11 = listcommandsplit[1].split(';')
	for i in range(int(var1)):
		listnamesplit = listname[i].split(' ')
		if listcommandsplit11[0] == listnamesplit[1]:
			listsorite.append(commandip + ' #' + listnamesplit[0])
for i in range(len(listsorite)):
	print(listsorite[i])


(a, b) = [int(i) for i in input().split()]
l = []
m = []
for i in range(a + b):
	s = str(input())
	if ';' in s:
		l.append(s)
	else:
		m.append(s)
for i in range(0, len(l)):
	e = l[i].find(' ')
	string = l[i][e:len(l[i]) - 1]
	for j in range(0, len(m)):
		if string in m[j]:
			p = m[j].find(' ')
			lstring = m[j][:p]
			print(l[i] + ' #' + lstring)


(n, m) = [int(x) for x in input().split()]
dic = {}
for i in range(n):
	a = input().split()
	dic[a[1]] = a[0]
for i in range(m):
	a = input().split()
	print(a[0] + ' ' + a[1] + ' ' + '#' + dic[a[1][:-1]])


(n, m) = map(int, input().split())
d = {}
lm = []
for x in range(n):
	a = input().split()
	d[a[1]] = a[0]
for x in range(m):
	b = input().split()
	print('{} #{}'.format(b[0] + ' ' + b[1], d[b[1][:-1]]))


(n, m) = map(int, input().split())
name = [None] * 1001
ip2 = [None] * 1001
act = [None] * 1001
d = dict()
for i in range(n):
	(name, ip) = input().split()
	d[ip] = name
for i in range(m):
	(act[i], x) = input().split()
	ip2[i] = x[:len(x) - 1]
for i in range(m):
	print(act[i] + ' ' + ip2[i] + '; #' + d[ip2[i]])


(n, m) = map(int, input().split())
a = []
c = []
b = []
d = []
for i in range(n):
	(l, k) = map(str, input().split())
	a.append(l)
	b.append(k)
for i in range(m):
	(l, k) = map(str, input().split())
	k = list(k)
	del k[-1]
	k = ''.join(map(str, k))
	print(l, end=' ')
	print(k, end='; ')
	print('#', end='')
	print(a[b.index(k)])


(x, y) = map(int, input().split())
a = [input().split() for i in range(x)]
for i in range(y):
	s = input().split()
	for j in range(len(a)):
		if s[1][0:len(s[1]) - 1] == a[j][1]:
			print(s[0], s[1], '#' + a[j][0])
			break


(x, y) = map(int, input().split())
n = list()
t = list()
for i in range(x):
	n.append(input().split())
for i in range(y):
	t.append(input().split())
for i in range(y):
	for j in range(x):
		l = t[i][1][0:len(t[i][1]) - 1]
		if l == n[j][1]:
			print(t[i][0], t[i][1], '#' + n[j][0])


(n, m) = map(int, input().split())
dic = {}
for i in range(n):
	(a, b) = input().split()
	dic[b] = a
for i in range(m):
	s = input()
	(a, b) = s.split()
	(b, _) = b.split(';')
	print(s, '#' + dic[b])


(n, m) = list(map(int, input().split()))
name = []
command = []
for i in range(n):
	name.append(list(map(str, input().split())))
for i in range(m):
	command.append(list(map(str, input().split())))
for i in range(m):
	text = str(command[i][0]) + ' ' + str(command[i][1]) + ' #'
	for j in range(n):
		if str(name[j][1]) + ';' in command[i]:
			text += name[j][0]
			break
	print(text)


(n, m) = input().split()
n = int(n)
m = int(m)
s1 = []
s2 = []
s3 = []
s4 = []
for i in range(0, n):
	(x, y) = input().split()
	s1.append(x)
	s2.append(y)
for i in range(0, m):
	(a, b) = input().split()
	s3.append(a)
	s4.append(b)
for i in range(0, m):
	print(s3[i], end=' ')
	print(s4[i], end=' ')
	z = s4[i].strip(';')
	for j in range(0, n):
		if z == s2[j]:
			print('#', end='')
			print(s1[j])


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	(a, b) = map(str, input().split())
	d[b] = a
for i in range(m):
	(z, x) = map(str, input().split())
	y = x[:len(x) - 1]
	if y in d:
		print(z + ' ' + x + ' #' + d[y])


a = list(map(int, input().split()))
servers = []
commands = []
output = []
for i in range(a[0]):
	temp = list(map(str, input().split()))
	servers.append(temp)
for i in range(a[1]):
	temp = list(map(str, input().split()))
	temp[1] = temp[1][:len(temp[1]) - 1]
	commands.append(temp)
for i in range(a[1]):
	for j in range(a[0]):
		if servers[j][1] == commands[i][1]:
			output.append(commands[i][0] + ' ' + commands[i][1] + '; #' + servers[j][0])
for i in output:
	print(i)


def main():
	(n, m) = map(int, input().split())
	d = dict()
	for i in range(n):
		(name, ip) = input().split()
		d[ip] = name
	for i in range(m):
		s = input()
		(com, ip) = s.split()
		ip = ip.strip(';')
		print(s + ' #' + d[ip])
main()


(n, m) = (int(x) for x in input().split())
s = []
d = []
p = []
q = []
for i in range(n):
	(a, b) = (x for x in input().split())
	s.append(a)
	d.append(b)
for i in range(m):
	(a, b) = (x for x in input().split())
	p.append(a)
	q.append(b)
for i in range(m):
	for j in range(n):
		if q[i] == d[j] + ';':
			z = p[i] + ' ' + q[i] + ' #' + s[j]
			print(z)


(n, m) = map(int, input().split())
d = dict()
for i in range(n + m):
	(name, ip) = input().strip(';').split()
	if ip in d:
		print('{} {}; #{}'.format(name, ip, d[ip]))
	else:
		d[ip] = name


a = []
a = list(map(int, input().split()))
n = a[0]
m = a[1]
mymap = {}
commands = []
for i in range(0, n):
	vin = list(input().split())
	mymap[vin[1]] = vin[0]
for i in range(0, m):
	command = input().strip(';')
	commands.append(command)
for i in range(0, m):
	command = commands[i]
	ip = list(command.split())[1]
	output = commands[i] + '; #' + mymap[ip]
	print(output)


import time

def timer(func):

	def f(*args, **kwargs):
		start_time = time.time()
		ret = func(*args, **kwargs)
		print('--- %s seconds ---' % (time.time() - start_time))
		return ret
	return f

def main():
	(n, m) = [int(x) for x in input().split()]
	servers = []
	for i in range(n):
		servers.append(input().split(' '))
	for i in range(m):
		line = input().split(' ')
		for j in range(n):
			if line[1][:-1] == servers[j][1]:
				print('{0} {1} #{2}'.format(line[0], line[1], servers[j][0]))
main()