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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'

size = map(int,raw_input().split())
n = size[0]
m = size[1]

matrix = {}

for i in range(n):
	rowl = map(int,raw_input().split())
	for j in range(m):
		matrix[rowl[j]] = (i,j)
		
#print matrix

q = int(raw_input())
 
for i in range(q):
	query = int(raw_input())
	if query in matrix:
		print "%d %d"%(matrix[query][0],matrix[query][1])
	else:
		print "%d %d"%(-1,-1)