n,m = map(int,raw_input().split())
a = []
for i in xrange(n):
    l = map(int,raw_input().split())
    a.append(l)
q = input()
for i in xrange(q):
    e = input()
    k = 0
    l = m-1
    while k<n and l>=0 and a[k][l]!=e:
    	if a[k][l]>e:
    		l-=1
    	else:
    		k+=1
    if k>=n or l<0:
    	print -1,-1
    else:
    	print k,l