from collections import defaultdict

def main():
	N, M = [int(i) for i in raw_input().split(' ')]
	if 2 <= N <= 1000 and 2 <= M <= 1000:
		output = []
		memories = defaultdict(list)
		for i in range(N):
			memories[i] = [int(m) for m in raw_input().split(' ')]

		Q = int(raw_input())

		for i in range(Q):
			query = int(raw_input())
			for X in memories:
				if query in memories[X]:
					output.append(str(X) + ' ' + str(memories[X].index(query)))
					break
			else:
				output.append('-1 -1')
		return output




if __name__ == '__main__':
	output = main()
	for out in output:
		print out