[n, m] = map(int,raw_input().split())
ma = {}
for i in xrange(n):
	rowl = map(int,raw_input().split())
	for j in range(m):
		ma[rowl[j]] = (i,j)
q = int(raw_input())
for i in range(q):
	query = int(raw_input())
	if query in ma:
		print "%d %d"%(ma[query][0],ma[query][1])
	else:
		print "%d %d"%(-1,-1)