n, m = map(int, raw_input().split())
a = [map(int, raw_input().split()) for _ in range(n)]
for _ in range(int(raw_input())):
	x = int(raw_input())
	found = 0
	for r in range(n):
		if x in a[r]:
			print r, a[r].index(x)
			found = 1
			break
	if not found:
		print -1, -1