n,m=map(int,raw_input().split())
mat=[]
for i in xrange(n):
    inp=raw_input().split()
    mat.append([int(inp[j]) for j in xrange(m)])        
q=int(raw_input())
while q:
    q=q-1
    x=int(raw_input())
    i=n-1
    j=0
    cord1=cord2=-1
    while(i>=0 and j<m and x<=mat[n-1][m-1]):        
        if(mat[i][j]==x):
            cord1=i
            cord2=j
            break
        if(mat[i][j]>x):
            i-=1
        else:
            j+=1
    print cord1,cord2