def dataGet(num,datalist):
        for i in range(0,len(datalist)):
                if num == datalist[i]:
                        return i

matrix_size = raw_input()
data = matrix_size.split(' ')
N = int(data[0])
M = int(data[1])

mind_palace = []
for i in range(0,N):

        data_element = raw_input()
        data_element_list = map(int,data_element.split(' '))
        mind_palace.append(data_element_list)

set_list = []
for i in mind_palace:
        set_list.append(set(i))


queries = raw_input()

for i in range(0,int(queries)):
        query = raw_input()
        found = False
        for j in range(0,len(set_list)):
                                
                if int(query) in set_list[j]:
                        
                        print '%s %s' % (j,dataGet(int(query),mind_palace[j]))
                        found = True
                        break
        if found == False:
                print '-1 -1'