n, m = map(int, raw_input().split())
dic = {}
for i in xrange(n):
	lst = map(int, raw_input().split())
	for j in xrange(m):
		dic[lst[j]] = [i, j]

q = input()
for i in xrange(q):
	key = input()
	if dic.has_key(key):
		print ' '.join(str(v) for v in dic[key])
	else: print -1, -1