def find():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    x = list(map(int, input().split()))
    sum_a = 0
    pref = {}
    for j in range(n):
        sum_a += a[j]
        if sum_a not in pref:
            pref[sum_a] = j
    for j in x:
        if j in pref:
            print(pref[j], end=' ')
        else:
            res = []
            for k in pref:
                if sum_a > 0 == (j - k) % sum_a:
                    res.append((j - k) // sum_a * n + pref[k])
            print(min(res) if res else -1, end=' ')
    print()


for i in range(int(input())):
    find()