n, m = map(int, raw_input().split())
a = [map(int, raw_input().split()) for _ in range(n)]

for i in range(int(raw_input())):
    flag = 0
    x = int(raw_input())
    for k in range(n):
        if x in a[k]:
            print k, a[k].index(x)
            flag = 1
            break
    if flag == 0:
        print "-1 -1"