#from heapq import *
#from math import *
from collections import *
from bisect import *
import sys
input=sys.stdin.readline
def inp():
    return int(input())
def st():
    return input().rstrip('\n')
def lis():
    return list(map(int,input().split()))
def ma():
    return map(int,input().split())     # HEY DEAR!!!
t=inp()
while(t):
    t-=1
    n,m=ma()
    a=lis()
    q=lis()
    pre=[0]
    for i in a:
        pre.append(pre[-1]+i)
    bpre=[]
    p=-1000000000000000000
    for i in range(1,n+1):
        if(p< pre[i] and pre[i]>0):
            bpre.append([pre[i],i])
            p=pre[i]
    for i in range(len(q)):
        x=q[i]
        if(a[0]>=x):
            print(0)
            continue
        if(len(bpre)):
            if(bpre[-1][0]>=x):
                    l=bisect_right(bpre,[q[i],1000000000])
                    if(l!=0):
                        print(bpre[l-1][1]-1,end=' ')
                        continue
        if(1):
            ha=pre[-1]
            if(len(bpre)==0 and ha<x and ha<=0):
                print(-1,end=' ')
                continue
            if(1):
                if(ha>0):
                    re=(x-1)//ha + 1
                    if(len(bpre)):
                        if(bpre[-1][0]>= (q[i]-((re-1)*ha))):
                            l=bisect_right(bpre,[q[i]-((re-1)*ha),100000000000])
                            if(l!=0):
                                print(min(re*n,((re-1)*n)+bpre[l-1][1]-1),end=' ')
                                continue
                    print(re*n,end=' ')
                else:
                    print(-1,end=' ')
    print()
                    
                    
                
