a = list(map(lambda x: int(x), raw_input().split()))
a0 = a[0]
a1 = a[1]
input_list = [[] for i in range(a0)]
for i in range(a0):
	input_list[i] = list(map(lambda x: int(x), raw_input().split()))

b = input()
list_num = []
for i in range(b):
	c = input()
	list_num.append(c)


def locate(obj,lst):
	x = 0
	y = a0 - 1
	while y >= 0  and x <= a1 - 1:
		tem = lst[y][x]
		if obj == tem:
			return y,x
		elif obj < tem:
			y -= 1
		else:
			x += 1
	return (-1, -1)
	
for i in list_num:
	y,x = locate(i,input_list)
	print str(y) + " " + str(x)