# your code goes here
n,m=(int(e) for e in raw_input().split())
def bsearch(arr,n):
	h=len(arr)-1
	l=0
	while l<h:
		m=(l+h)/2
		if arr[m][0] >=n:
			h=m
		else:
			l=m+1
	return l
	
arr=[]
for i in xrange(n):
	temp=[int(e) for e in raw_input().split()]
	for j in xrange(m):
		arr.append((temp[j],i,j))
arr.sort(key=lambda x:x[0])
q=int(raw_input())
for i in xrange(q):
	n=int(raw_input())
	ind=bsearch(arr,n)
	if arr[ind][0]==n:
		print arr[ind][1],arr[ind][2]
	else:
		print -1,-1