#include<bits/stdc++.h>
using namespace std;
#define inf 0x7fffffff
#define timeused() (double)clock()/CLOCKS_PER_SEC
#define rep(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define repp(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define debug() assert(0)
typedef long long ll;
typedef unsigned long long ull;
template<typename T> inline T rd(T& x){
   T f=1;x=0;char c=getchar();
   for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
   for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(T)(c-'0');
   x*=f;
   return x;
}
ll t,n,m,x[1000005],a[1000005],qzh[1000005],maxpre;
struct node{
   ll v,pos;
}q[1000005];
bool cmp(node x,node y){return x.v==y.v?x.pos<y.pos:x.v<y.v;}
int main(){
   rd(t);
   while(t--){
      maxpre=-inf;
      rd(n);
      rd(m);
      rep(i,1,n) rd(a[i]);
      rep(i,1,n) qzh[i]=qzh[i-1]+a[i];
      rep(i,1,n) maxpre=max(maxpre,qzh[i]);
      rep(i,1,n){
         q[i].pos=i;
         q[i].v=qzh[i];
      }
      sort(q+1,q+n+1,cmp);
      rep(i,1,m) rd(x[i]);
      rep(i,1,m){
         ll ans=0;
         if(maxpre<x[i]&&qzh[n]<=0){
            printf("-1 ");
            continue;
         }
         if(x[i]>maxpre){
            ans+=n*ceil(1.0*(x[i]-maxpre)/qzh[n]);
            x[i]-=qzh[n]*ceil(1.0*(x[i]-maxpre)/qzh[n]);
         }
         if(!x[i]){
            printf("%lld ",ans-1);
            continue;
         }
         ll l=1,r=n;
         while(r-l>1){
            ll mid=(l+r)/2;
            if(q[mid].v>=x[i]) r=mid;
            else l=mid+1;
         }
         if(q[l].v<x[i]) ++l;
         ans+=q[l].pos;
         printf("%lld ",ans-1);
      }
      puts("");
   }
}