memo={}
x,y=map(int,raw_input().split())
for row in xrange(x):
	a = map(int,raw_input().split())
	for i,j in enumerate(a):
		n,m=str(row)+" ",str(i)
		memo[j] = n+m
		
	

		
for _ in xrange(input()):
	query = int(input())
	if query in memo:
		print memo[query]
	else:
		print -1,-1