'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def process(arr, ip, r, c):
	currentRow = 0
	currentCol = c-1
	while(currentRow>=0 and currentCol>=0 and currentRow < r and currentCol < c) :		
		if arr[currentRow][currentCol] == ip:
			return [currentRow,currentCol]
		elif arr[currentRow][currentCol] > ip:
			currentCol = currentCol-1			
		else:
			currentRow = currentRow+1
	return [-1,-1]

temp = raw_input()
temp = temp.split()
N = int(temp[0])
M = int(temp[1])
arr = []

for i in range(N):
	temp = raw_input()
	temp = temp.split()
	temp = [int(elem) for elem in temp]
	arr.append(temp)

Q = int(raw_input())
for i in range(Q):
	ip = int(raw_input())
	op = process(arr, ip, N, M)
	print op[0], op[1]