import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
t=int(input())
for _ in range(t):
  n,m=map(int,input().split())
  a=list(map(int,input().split()))
  b=list(map(int,input().split()))
  rui=[0]
  tmp=0
  for i in range(n):
    tmp+=a[i]
    rui.append(tmp)
    
  tmp=-1
  best=[]
  for i in range(n+1):
    if rui[i]>tmp:
      tmp=rui[i]
      best.append((tmp,i))
  k=sum(a)
  p=max(rui)
  ans=[]
  for i in range(m):
    x=b[i]
    if k<=0 and x>p:
      ans.append(-1)
      continue
    if k<=0:
      l=0
      r=len(best)+1
      while l+1<r:
        try1=(l+r)//2
        if best[try1][0]>=x:
          r=try1
        if best[try1][0]<=x:
          l=try1
      try1=l
      while best[l][0]<x:
        l=l+1
      while l>0 and best[l-1][0]>=x:
        l-=1
      ans.append(best[l][1]-1)
    else:
      if (x-p)%k!=0:
        rot=(x-p)//k+1
      else:
        rot=(x-p)//k
      x-=rot*k
      l=0
      r=len(best)+1
      while l+1<r:
        try1=(l+r)//2
        if best[try1][0]>=x:
          r=try1
        if best[try1][0]<=x:
          l=try1
      while best[l][0]<x:
        l=l+1
      while l>0 and best[l-1][0]>=x:
        l-=1
      ans.append(n*rot+best[l][1]-1)
  print(' '.join(map(str,ans)))