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

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

def position(d,q):
	q=str(q)
	if q in d:
			return d[q]
	else:
		return '-1 '+'-1'		
	
m,n=raw_input().split(' ')
m,n=int(m),int(n)
i=0
d=dict()
while i<m:
	num=0
	l=raw_input().split(' ')
	l=list(l)
	while num<len(l):
		d[l[num]]=str(i)+' '+str(num)
		num=num+1
	i=i+1	
q=int(raw_input())
for j in range(q):
	q1=int(raw_input())
	print position(d,q1)