n,m = map(int,raw_input().split())
dime = []

def saddleback_search(dime,y):
	row,col = 0,m-1
	while 0<= row < n and 0<= col < m:
		if dime[row][col] < y:
			row += 1
		elif dime[row][col] > y:
			col -= 1
		elif dime[row][col] == y:
			return row,col
	return -1,-1

for i in xrange(n):
	row = map(int,raw_input().split())
	dime.append(row)
q = input()
for i in xrange(q):
	y = input()
	t1,t2 = saddleback_search(dime,y)
	print "%d %d" % (t1,t2)