import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class G702 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        for (int ff = 0; ff < t; ff++) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken()), m = Integer.parseInt(st.nextToken());
            int[] ar = new int[n];
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < n; i++)
                ar[i] = Integer.parseInt(st.nextToken());
            int maxadd = ar[0];
            //the value difference we can achieve -> the least index for that value
            TreeMap<Integer, Integer> tm = new TreeMap<Integer, Integer>();
            tm.put(ar[0], 1);
            for (int i = 1; i < n; i++) {
                ar[i] += ar[i - 1];
                maxadd = Math.max(maxadd, ar[i]);
                if(!tm.containsKey(ar[i]))
                    tm.put(ar[i], i + 1);
            }
            int endadd = ar[n - 1];
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < m; i++) {
                int q = Integer.parseInt(st.nextToken());
                if(tm.lastKey() >= q){
                    int ans = 0;
                    if(tm.containsKey(q)){
                        ans = tm.get(q) - 1;
                    }else{
                        ans = tm.higherKey(q) - 1;
                    }
                    System.out.print(ans + " ");
                    continue;
                }
                if(maxadd <= 0){
                    System.out.print(-1 + " ");
                    continue;
                }
                int get = (int) Math.ceil(((double)(q - maxadd)) / ((double)endadd));
                if(get == 0)
                    continue;
                if(get < 0){
                    System.out.print(-1 + " ");
                    continue;
                }
                int curval = q - get * endadd;
                if(tm.containsKey(curval)){
                    int ans = tm.get(curval) + get * n - 1;
                    System.out.print(ans + " ");
                }else{
                    if(tm.lastKey() < curval)
                        System.out.print(-1 + " ");
                    else {
                        int ans = tm.higherKey(curval) + get * n - 1;
                        System.out.print(ans + " ");
                    }
                }
            }
            System.out.println();
        }
    }
}
