m,n = map(int, raw_input().split())
r=0
c=0
matrix = list()
for i in range(m):
	matrix.append(map(int,raw_input().split()))
			
t = int(raw_input())
for z in range(t):
	w = int(raw_input())
	i=m-1
	j=0
	flag=1
	while i>-1 and j<n:
		if matrix[i][j]==w:
			print i,j
			flag = 0
			break
		elif matrix[i][j]>w:
			i-=1
		else:
			j+=1
	if flag==1:
		print "-1 -1"