x, y = map(int, raw_input().split())
d = {}
for i in xrange(x):
    a = raw_input().split()
    for j in xrange(y):
        d[a[j]]= '%d %d'%(i,j)
#print d
for k in xrange(int(raw_input())):
    print d.get(raw_input(), '-1 -1')