'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t= raw_input().split()
n= int(t[0])
m =int(t[1])
matrix = {}
if m>=2 and n<=1000:
	for i in xrange (n):
		rows = map(int, raw_input().split())
		for j in range(m):
			matrix[rows[j]]= i,j

q = int(raw_input())
if q >=2 and q<=1000:
	for _ in xrange (q):
		a = int(raw_input())
		if matrix.get(a):
			print matrix[a][0],matrix[a][1]
			
		else:
			print "-1 -1"