input_sizes = raw_input()
sizes = []
for size in input_sizes.split():
	sizes.append(int(size))
count = 0
mat = []
while count < sizes[0]:
	numbers = []
	text_input = raw_input()
	for num in text_input.split():
		numbers.append(int(num))
	mat.append(numbers)
	count += 1
test_cases  = raw_input()
test_cases = int(test_cases)
count = 0
while count < test_cases : 
	num = raw_input()
	num = int(num)
	row = 0 
	col = sizes[1]-1
	while 1:
		if(row == sizes[0] or  col == -1):
			print "-1 -1"
			break
		if(num == mat[row][col]):
			print str(row)+" "+str(col)
			break
		elif(num > mat[row][col]):
			row += 1
		else:
			col -= 1
	count += 1