size=[int(x) for x in raw_input().split()]
dic={}

for i in xrange(0,size[0]):
    mem=[int(x) for x in raw_input().split()]
    for j in xrange(0,size[1]):
        dic[mem[j]]=str(i)+" "+str(j)


q=input()

for k in xrange(0,q):
    query=input()
    if dic.has_key(query):
        print dic[query]
    else:
        print -1,-1