def inputi():
    return int(input())
def inputli():
    return list(map(int,input().split(' ')))
def inputls():
    return list(map(str,input().split(' ')))


def print_list(lista):
    s=""
    for i in lista[:-1]:
        s+=str(i)+" "
    s+=str(lista[-1])

    return s


def query_process(sumas,numbers,query):

    if sumas[len(numbers)-1] ==0 :
        for id,suma in enumerate(sumas):
            if query == suma:
                return id
        return -1
    else:
        # x * sumas[len(numbers)-1] + sumas[i] = query
        mini = 2000000
        for id in range(len(numbers)):
            #print(x,query,sumas[id],sumas[len(numbers)-1])
            x = (query-sumas[id])/sumas[len(numbers)-1]
            if x == int(x) and x>=0:
                mini = min(mini,int(x*len(numbers)+id))
        if mini!=2000000:
            return mini
        return -1


def solve():
    [n,m] = inputli()
    numbers = inputli()
    queries = inputli()

    ans = []

    sumas = []
    back =0
    for i in numbers:
        sumas.append(back+i)
        back+=i
    #print(sumas)
    for id, query in enumerate(queries):
        ans.append(query_process(sumas,numbers,query))

    return ans


   
t = inputi()


for i in range(t):

    ans = solve()
    print(print_list(ans),end='')
    print('') if i!=(t-1) else None
