import java.util.*;

public class Main5 {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-->0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            long[] nn = new long[n];
            long[] mm = new long[m];
            for(int i=0;i<n;i++){
                nn[i]=sc.nextInt();
            }
            for(int i=0;i<m;i++){
                mm[i]=sc.nextInt();
            }
            HashMap<Long,Integer> map = new HashMap<>();
            long[] cum = new long[n];
            for(int i=0;i<n;i++){
                if(i==0){
                    cum[i]=nn[i];
                }else{
                    cum[i]=cum[i-1]+nn[i];
                }
                map.put(cum[i],i);
            }
            for(int i=0;i<m;i++){
                long x=mm[i];
                if(map.containsKey(x)){
                    System.out.print(map.get(x)+" ");
                    continue;
                }
                if(cum[n-1]==0){
                    if(map.containsKey(x)){
                        System.out.print(map.get(x)+" ");
                    }else{
                        System.out.print(-1+" ");
                    }
                }else{
                    long q = x/cum[n-1];
                    long r = x-q*cum[n-1];
                    if(r==0){
                        System.out.print(n*Math.abs(q)-1+" ");
                    }else{
                        if(map.containsKey(r)){
                            System.out.print(n*Math.abs(q)+map.get(r)+" ");
                        }else{
                            System.out.print(-1+" ");
                        }
                    }

                }

            }
            System.out.println();

        }

    }


}
