from sys import stdin as cin

def main():
    line = cin.readline().strip()
    a = line.split(" ")
    R,C = int(a[0]),int(a[1])
    m = []
    for t in range(0,R):
        line = cin.readline().strip()
        arr = line.split(" ")
        lst = [int(x) for x in arr]
        m.append(lst)
    T = int(input())
    for t in range(0,T):
        n = int(input())
        found  = False
        r,c = 0,C-1
        while(r < R and c >=0 ):
            if(m[r][c] == n):
                print(str(r) +' '+ str(c))
                found = True
                break
            elif m[r][c] < n:
                r = r + 1
            elif m[r][c] > n:
                c = c - 1
        if not found:
            print( str('-1') +' '+str('-1'))
main()