import sys
rows,columns = map(int,sys.stdin.readline().split())
master_dict = {}
for row in xrange(rows):
	rowlist = map(int,sys.stdin.readline().split())
	for column in xrange(columns):
		master_dict[rowlist[column]] = (row,column)
queries = int(sys.stdin.readline())
for i in xrange(queries):
	query = int(sys.stdin.readline())
	if query in master_dict:
		sys.stdout.write("{0} {1}\n".format(master_dict[query][0],master_dict[query][1]))
	else:
		sys.stdout.write("{0} {1}\n".format(-1,-1))