def main():
	N, M = map(int, raw_input().split())
	mem = []
	for i in range(0, N):
		mem.append(list(map(int, raw_input().split())))
	Q = int(raw_input())
	for i in range(0, Q):
		X = int(raw_input())
		
		xx = 0
		yy = M-1
		flag = 0
		while xx<N and yy>=0:
			if X>mem[xx][yy]:
				xx = xx+1
			else:
				if X<mem[xx][yy]:
					yy = yy-1
				else:
					print xx, yy
					flag = 1
					break
		if flag==0:
			print "-1 -1"
main()