'''
Created on 16/12/2014

@author: also
'''
from bisect import bisect_left

def binary_search(a, x, lo=0, hi=None):   # can't use a to specify default for hi
    hi = hi if hi is not None else len(a) # hi defaults to len(a)   
    pos = bisect_left(a,x,lo,hi)          # find insertion position
    return (pos if pos != hi and a[pos] == x else -1) # don't walk off the end

n,m=[int(x) for x in raw_input().split()]
matrix = [[] for item in range(0,n)]

for i in range(0,n):
    matrix[i] = [int(x) for x in raw_input().split()]
q=int(raw_input())
for i in range(0,q):
    q2=int(raw_input())
    y = -1
    x=-1
    for i2 in range(0,n):
        retorno = binary_search(matrix[i2],q2)
        if (retorno != -1):
            x=i2
            y=retorno
            break
    print "{0} {1}".format(x,y)