def solve(memory,n,m,x):
	i = 0;
	j = m - 1;
	while i<n and j>=0:
		if memory[i][j]==x:
			print i,j
			return
		elif memory[i][j]>x:
			j=j-1
		else:
			i=i+1
	print -1,-1
	
	
n,m = map(int,raw_input().split())
memory = []
for i in range(n):
	memory.append(map(int,raw_input().split()))
q = int(raw_input())
for i in range(q):
	query = int(raw_input())
	solve(memory,n,m,query)