n,m = map(int, raw_input().split())
palace = [[0]*m for x in xrange(n)]
val_dict = {}
for i in xrange(n):
	j = 0
	for jj in map(int,raw_input().split()):
		palace[i][j] = jj
		val_dict[jj] = (i,j)
		j += 1

q = int(raw_input())
for i in xrange(q):
	query = int(raw_input())
	if query not in val_dict:
		print "-1 -1"
		continue
	print "%d %d" % val_dict[query]