// Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;






// Please name your class Main
public class Main {
    static Scanner in = new Scanner(System.in);
    public static void main (String[] args) throws java.lang.Exception {
        PrintWriter out = new PrintWriter(System.out);

        int T=Int();
        for(int t=0;t<T;t++){
            int n=Int();int m=Int();
            int A[]=new int[n];
            int B[]=new int[m];
            for(int i=0;i<n;i++){
                A[i]=Int();
            }

            for(int i=0;i<m;i++){
                B[i]=Int();
            }

            Solution sol=new Solution();
            sol.solution(A,B);

        }
        out.flush();
    }

    public static long Long(){
        return in.nextLong();
    }
    public static int Int(){
        return in.nextInt();
    }
    public static String Str(){
        return in.next();
    }
}


class Solution{
    public void solution(int A[],int B[]){
        int n=A.length,m=B.length;
        int res[]=new int[m];

        //prefix sum
        long pre[]=new long[A.length];
        long maxs[]=new long[A.length];
        pre[0]=A[0];
        maxs[0]=A[0];

        for(int i=1;i<n;i++){
            pre[i]=pre[i-1]+A[i];
            maxs[i]=Math.max(pre[i],maxs[i-1]);
            //System.out.println(maxs[i]);
        }


        //find the first one that is >= query

        for(int q:B){
            if(maxs[n-1]<q){//need cycle
                if(pre[n-1]<=0){//infinite loop
                    System.out.print(-1+" ");
                    continue;
                }

                long cycle=(q-maxs[n-1])/(pre[n-1]);
                if((q-maxs[n-1])%(pre[n-1])!=0){
                    cycle++;
                }
                q-=(cycle*pre[n-1]);
                int pos=bin(maxs,q);
                System.out.print((cycle*n+pos)+" ");

            }
            else{//no cycle
                int pos=bin(maxs,q);
                System.out.print(pos+" ");
            }

        }
        System.out.println();
    }

    public int bin(long maxs[],long q){
        int l=0,r=maxs.length-1;
        int res=-1;
        while(l<=r){
            int mid=l+(r-l)/2;
            if(maxs[mid]>=q){
                res=mid;
                r=mid-1;
            }
            else{
                l=mid+1;
            }
        }
        return res;
    }


}