# Read input from stdin and provide input before running code

dim = raw_input().split()
m,n = int(dim[0]),int(dim[1])
arr = []
queries = []
for i in range(m):
	row = raw_input()
	arr.append(map(int, row.split()))
query_count = int(raw_input())

for i in range(query_count):
	queries.append(int(raw_input()))
	
def checkElement(item, row, col, m, n):
	r = row
	c = col
	while True:
		if item == arr[r][c]:
			return r,c
		elif item < arr[r][c]:
			c = c-1
		elif item > arr[r][c]:
			r = r+1
		if c < 0 or r > m:
			return -1,-1
			
for q in queries:
	r,c = checkElement(q, 0, n-1, m-1, n-1)
	print('%d %d' % (r, c))