m,n=map(int,raw_input().split())
dict={}
for p in range(m):
    li=[i for i in raw_input().split()]
    for i in range(n):
    	dict[li[i]]=p,i
q=int(raw_input())
for i in range(q):
	o=raw_input()
	if dict.get(o):
		(x,y)=dict[o]
		print x,y;
	else:
		print("-1 -1")