from itertools import product
from collections import Counter

taringud=[]
elud=[]
ntaringud, nelud = map(int, input().split())
tabel = []
#tabel=[0*nelud for i in range(ntaringud)]
for i in range(ntaringud):
    taringud.append(input())
for i in range(nelud):
    elud.append(int(input()))
    tabel.append([])
    
#Arvuta iga täringu jaoks tõenäosused                    
for i in range (ntaringud):
    n, tahke, bonus = map(int, taringud[i].split())
    
    # Kõik võimalikud visked
    visked = product(range(1, tahke+1), repeat=n)

    # Loeme summad
    sums = [sum(vise) for vise in visked]
 
    # Loendame iga summa esinemiskordi
    count = Counter(sums)

    #kokku erinevaid võimalusi
    voimalusi = tahke**n
    for j in range(nelud):
        kokku = 0
        for k in range(elud[j]-bonus):
            kokku += count[k]
        tabel[j].append(float((voimalusi-kokku)/float(voimalusi)))
for i in range(nelud):
    print(tabel[i].index(max(tabel[i]))+1)
    
# print(tabel)
