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()]
	tmp = []
	mat = {}
	for i in xrange(N):
		tmp = [int(x) for x in raw_input().split()]
		for j in xrange(M):
			mat[tmp[j]]=(i,j)
		
	Q=int(raw_input())
	for _ in xrange(Q):
		q=int(raw_input())
		if q in mat:
			print mat[q][0],mat[q][1]
		else:
			print -1,-1
		
main()