N,M=[int(x) for x in raw_input().split()]

matrix=[]

for i in xrange(0,N):
    row=[int(x) for x in raw_input().split()][:M]
    matrix.append(row)

Q=int(raw_input())

for x in xrange(0,Q):
    memory=int(raw_input())
    start,end=0,M-1

    while(start<N and end>=0):
         if(matrix[start][end]==memory):
             break;
         elif(matrix[start][end]<memory):
             start=start+1
         else:
             end=end-1

    if (start==N or end<0):
        print "-1 -1"
    else:
        print str(start)+" "+str(end)