import java.util.*;
import java.io.*;
public class Main
{
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
    static class Pair
    {
        int f,s;
        Pair(int f,int s)
        {
            this.f=f;
            this.s=s;
        }
    }
    public static void main(String args[])
    {
        FastReader fs=new FastReader();
        PrintWriter pw=new PrintWriter(System.out);
        int tc=fs.nextInt();
        while(tc-->0)
        {
            int n=fs.nextInt();
            int m=fs.nextInt();
            long a[]=new long[n];
            for(int i=0;i<n;i++)
            a[i]=fs.nextLong();
            long x[]=new long[m];
            for(int i=0;i<m;i++)
            x[i]=fs.nextLong();
            long pref[]=new long[n];
            pref[0]=a[0];
            ArrayList<Long> prefMax=new ArrayList<>();
            ArrayList<Integer> ind=new ArrayList<>();
            prefMax.add(a[0]);
            ind.add(0);
            for(int i=1;i<n;i++)
            {
                pref[i]=pref[i-1]+a[i];
                if(pref[i]>prefMax.get(prefMax.size()-1))
                {
                    prefMax.add(pref[i]);
                    ind.add(i);
                }
            }
            int sz=prefMax.size();
            for(int i=0;i<m;i++)
            {
                if(prefMax.get(sz-1)<=0)
                {
                    pw.print("-1 ");
                    continue;
                }
                if(pref[n-1]<=0)
                {
                    int l=-1,r=sz;
                    while(r-l>1)
                    {
                        int mid=(l+r)/2;
                        if(prefMax.get(mid)<x[i])
                        l=mid;
                        else
                        r=mid;
                    }
                    if(r!=sz)
                    pw.print(r+" ");
                    else
                    pw.print("-1 ");
                    continue;
                }
                long req=0;
                if(prefMax.get(sz-1)<x[i])
                req=(x[i]-prefMax.get(sz-1)+pref[n-1]-1)/pref[n-1];
                x[i]-=req*pref[n-1];
                int l=-1,r=sz;
                while(r-l>1)
                {
                    int mid=(l+r)/2;
                    if(prefMax.get(mid)<x[i])
                    l=mid;
                    else
                    r=mid;
                }
                pw.print((req*n+ind.get(r))+" ");
            }
            pw.println();
        }
        pw.flush();
        pw.close();
    }
}