#include <bits/stdc++.h> 
#include <string>
#include <cmath> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef map<int,int> mpii;
typedef map<int,vi> mpivi;
typedef map<string,int> mpsi;
typedef map<pii,int> map_pair;
typedef set<int> seti;
#define	bits(n)						( (n==0)?0:((int)log2(n)+1) )
#define endl "\n"
#define FOR(i,n) SFOR(i,0,n)
#define SFOR(i,m,n) for(i=m;i<n;i++)
#define FORD(i,n) for(i=n-1;i>=0;i--)
#define digits(i)   (int)((log(i)/log(10))+1)		
#define inf							(int)1e9
#define eps							1e-9
#define pi							3.1415926535897932384626433832795
#define mod							1000000007
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) s.size()
#define si(t) scanf("%d",&(t))
#define ss(t) scanf("%s",(t))
#define sll(t) scanf("%lld",&(t))
#define maX(a,b)					( (a) > (b) ? (a) : (b))
#define miN(a,b)					( (a) < (b) ? (a) : (b))
#define check_bit(var,pos) ((var) & (1<<(pos)))
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define prn1(x)                cout<<#x<<": "<<x<<endl
#define prn2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define prn3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define prn4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define prn5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define prn6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

struct myfun
{
    public:
bool operator()(pair<double,double> a,pair<double,double>  b)
{
    return a.second/a.first<=b.second/b.first;
}
};

long long inverse(long long a, long long b){
 return 1<a ? b - inverse(b%a,a)*b/a : 1;
}
void A()
{
    int t;
    cin>>t;
    for(int kk=0;kk<t;kk++)
    {     
       ll n;
       cin>>n;
       vi vec(n);
       map<int, int> mp;
       for(int i=0;i<n;i++)
       {
           cin>>vec[i];
           mp[vec[i]]++;
       }
       vll fre;
       for(int i=0;i<n;i++)
       {
           if(mp[vec[i]])
           {
              // prn3(i,vec[i],mp[vec[i]]);
               fre.pb((ll)mp[vec[i]]);
               mp[vec[i]]=0;
           }
       }
       sort(all(fre));
       int m=fre.size();
       vll sm(m);
       ll sum=0;
       for(int i=0;i<m;i++)
       {
           sum+=fre[i];
           sm[i]=sum;
       }
       ll ans=n;
       for(int i=0;i<m;i++)
       {
           ll temp=0;
           if(i>0)
           {
               temp+=sm[i-1];
           }
           ll nex=sum-sm[i];
           ll re= (m-1-i);
           re =re*fre[i];
           //prn4(i,temp,nex,re);
           temp+= (nex-re);
           ans=min(ans,temp);
       }
       cout<<ans<<endl;
    }
}
void B()
{
    int t;
    cin>>t;
    for(int kk=0;kk<t;kk++)
    {
      ll n,m;
      cin>>n>>m;
      vll vec(n);
      ll sum=0;
      map<ll,int> mp;
      for(int i=0;i<n;i++)
      {
          cin>>vec[i];
          sum+=vec[i];
          if(!mp[sum]) mp[sum]=i+1;
         // prn2(sum,i+1);
      }
      //prn1(sum);
      vll qu(m);
      for(int i=0;i<m;i++)
      {
          cin>>qu[i];
          ll a= qu[i];
          if(mp[a])
          {
              cout<< (ll)mp[a] -1<<" ";
              continue;
          }
          ll b =0;
        if( (a>0 && sum>0)||(a<0 && sum<0))
            b= a/sum;
        if( (a>0 && sum>0)||(a<0 && sum<0))
           a= a%sum;
          if(a==0 && qu[i]!=0) {a=sum; b--;}
        //  prn5(i,qu[i],a,b,mp[a]);
          if(mp[a])
          {
              cout<< ((ll)b*(ll)n) + (ll)mp[a] -1<<" ";
          }
          else
              cout<<"-1 ";
      }
      cout<<endl;
      
    }
}
int main() {
    boost;
    #if !ONLINE_JUDGE && !EVAL
    freopen("C:\\Users\\asderfers\\Documents\\codeforce\\hello\\in.txt", "r", stdin);
    //freopen("J.txt", "r", stdin);
    #endif
    B();
    return 0;
} 