from sys import stdin, stdout
import math
input = stdin.readline

tc = 1
tc = int(input())
for _ in range(tc):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    x=list(map(int,input().split()))
    s=[a[0]]
    for i in range(1,n):
        s.append(s[-1]+a[i])
    ss=s[-1]
    mx=max(s)
    for i in x:
        if ss<=0 and mx<i:
            print(-1,end= ' ')
            continue
        if i<0:
            for j in range(n):
                if s[j]>=i:
                    print(j,end=' ')
                    break
            continue
        try:
            r = max(0, (i-mx)//ss)
        except:
            r=0
        re = i-r*(ss)
        r*=n
        j=0
        while(re>0):
            re-=a[j%n]
            j+=1
            r+=1
        r-=1
        print(r,end=' ')
    print()