def find(m,q):
	N=len(m)
	M=len(m[0])
	i=0
	j=M-1
	while(i<N and j>=0):
		if m[i][j] == q:
			return (i,j)
		elif m[i][j]<q:
			i=i+1
		else:
			j=j-1
	
	return (-1,-1)
	




def main():
	N,M = [int(x) for x in raw_input().split()]
	mat = []
	for _ in xrange(N):
		mat.append([int(x) for x in raw_input().split()])
		
	Q=int(raw_input())
	for _ in xrange(Q):
		X,Y = find(mat,int(raw_input()))
		print X,Y
		
main()