def fun(arr,n,m,q):
	for i in range(n):
		curr = arr[i]
		l = len(curr)
		high = l - 1
		low = 0
		while(low <= high):
			mid = ( low + high) /2 
			if (curr[mid] > q):
				high = mid - 1
			elif (curr[mid] < q):
				low = mid + 1
			else:
				return i,mid
	return (-1,-1)
		


n,m = map(int,raw_input().split())
arr = []
for i in range(n):
	arr.append(list(map(int,raw_input().split())))

query = int(raw_input())

#print query
#print arr
#print n, m

for each in range(query):
	q = int(raw_input())
	x,y = fun(arr,n,m,q)
	print x,y