#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
ll num[200009];
ll sum[200009];
ll ans[200009];
struct QU{
    ll num;
    ll id;
    bool operator < (QU B){
        return num<B.num;
    }
};
QU qu[200009];
map<ll,ll> mp;
int main(){
    int t;
    cin>>t;
    while(t--){
        ll n,m;
        cin>>n>>m;
        mp.clear();
        for(int i=1;i<=n;i++) cin>>num[i];
        for(int i=1;i<=m;i++) {cin>>qu[i].num;qu[i].id=i;}
        sort(qu+1,qu+1+m);
        ll bg=1;
        ll round=0;
        ll maxx=0;
        for(int i=1;i<=n;i++){
            sum[i]=sum[i-1]+num[i];
            //cout<<sum[i]<<"@@@"<<endl;
            if(sum[i]>=qu[bg].num){
                while(sum[i]>=qu[bg].num&&bg<=m){
                    ans[qu[bg].id]=i-1;
                    bg++;
                }
            }
            if(i==n) round=sum[n];
            if(sum[i]>maxx){
                mp[sum[i]]=i;
            }
            maxx=max(maxx,sum[i]);
        }
        cout<<maxx<<"!!!\n";
        if(round<=0) {
            for(int i=bg;i<=m;i++) {ans[qu[i].id]=-1;}
        }else{
            for(int i=bg;i<=m;i++){
                ll now=qu[i].num;
                ll temp=(now-maxx)%round ? 1:0;
                ll okk=((now-maxx)/round+temp)*n-1;
                cout<<(now-maxx)<<endl;
                ll cha=now-((okk+1)/n*round);
                okk+=mp.lower_bound(cha)->second;
                ans[qu[i].id]=okk;
            }
        }
        for(int i=1;i<=m;i++){
            cout<<ans[i]<<" ";
        }
        cout<<endl;
    }


}
