n,m=map(int,raw_input().split())
val={}
for i in xrange(n):
	j=0
	for k in map(int,raw_input().split()):
		val[k]=(i,j)
		j+=1
for _ in xrange(input()):
	x=input()
	if x in val:
		print "%d %d " %val[x]
	else:
		print "-1 -1"