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

Solutions:
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) = 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().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])


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)


(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) = 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) = 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=' ')


(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])


(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(';')]))


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) = [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]))


(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) = [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])


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])])


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(' '))
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, 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) = [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]))


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())
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)


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) = 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())
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())
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) = [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()