t = int(input())
ans = ""

for i in range(t):
    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    x = list(map(int, input().split()))

    total = sum(a)
    greatest = max(a)
    

    for j in range(m):
        seconds = 0
        count = 0
        index = 0
        if (x[j] <= greatest):
            while count < x[j]:
                count += a[index]
                seconds += 1
                index += 1
                if index == n:
                    if total <= 0:
                        seconds = 0
                        count = x[j]
                    index = 0
        else:
            if (total != 0):
                seconds = int((x[j]-greatest)/total)*n
                count = total * int((x[j]-greatest)/total)
            if total <= 0:
                seconds = 0
                count = x[j]
            while count < x[j]:
                count += a[index]
                seconds += 1
                index += 1
                if index == n:
                    index = 0
        ans += str(seconds-1) + " "
    ans += "\n"
print(ans)
		  		 		    	  	  	      	  	