def bs(t,arr):
    low=0
    high=len(arr)-1
    while low<=high:
        mid=(low+high)/2
        if arr[mid]<t:
            low=mid+1
        elif arr[mid]==t:
            return [1,mid]
        else:
            high=mid-1
    return [0,5]

n,m=map(int,raw_input().split())
arr=[]
for i in range(n):
    arr.append(map(int,raw_input().split()))
#print arr
for _ in range(input()):
    x=input()
    enum=0
    for item in arr:
        if bs(x,item)[0]==1:
            print enum,bs(x,item)[1]
            break
        enum+=1
    else:
        print -1,-1