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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''

		
#Mind Palace
import sys
 
m,n = map(int,sys.stdin.readline().split())
matrix = {}
for row in range(m):
	rowlist = map(int,sys.stdin.readline().split())
	for column in range(n):
		matrix[rowlist[column]] = (row,column)
queries = int(sys.stdin.readline())
for i in range(queries):
	query = int(sys.stdin.readline())
	if query in matrix:
		sys.stdout.write("{0} {1}\n".format(matrix[query][0],matrix[query][1]))
	else:
		sys.stdout.write("{0} {1}\n".format(-1,-1))