import java.util.*;
import java.io.*;

public class Main {

    private static final FastIO fastIO = new FastIO();
    private static final String yes = "YES";
    private static final String no = "NO";

    public static void main(String[] args) {
        int t = fastIO.nextInt();

        while(t-- > 0){
            int n = fastIO.nextInt();
            int m = fastIO.nextInt();
            long[] a = new long[n];
            long[] x = new long[m];
            long[] ans = new long[m];
            long max = 0;
            long add = 0;
            Map<Long, Integer> map = new HashMap<>();
            map.put(0L, 0);

            for(int i = 0; i < n; i++) {
                a[i] = fastIO.nextLong();
                add += a[i];
                max = Math.max(max, add);

                if(add != 0)
                    map.put(add, i + 1);
            }

            for(int i = 0; i < m; i++) {
                x[i] = fastIO.nextLong();

                if(add > 0) {
                    long count = x[i] / add;
                    ans[i] += count * n;
                    x[i] %= add;
                } else if(x[i] > max)
                    x[i] = -1;
            }

            for(int i = 0; i < m; i++){
                if(map.containsKey(x[i])){
                    fastIO.append(ans[i] + map.get(x[i]) - 1, " ");
                } else {
                    fastIO.append(-1, " ");
                }
            }

            fastIO.appendln();
        }

        fastIO.printAll();
    }

    public static class Node {

    }

    private static class FastIO {

        private final BufferedReader in;
        private final StringBuilder out;
        private final char LINE_BREAK = '\n';

        private StringTokenizer tokens;

        public FastIO() {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new StringBuilder();
        }

        public String next() {
            while (tokens == null || !tokens.hasMoreElements()) {
                try {
                    tokens = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            return tokens.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String str = "";

            try {
                str = in.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return str;
        }

        public FastIO append(Object... objects){
            for(Object o: objects)
                out.append(o);
            return this;
        }

        public FastIO appendln(Object... objects){
            return append(objects).append(LINE_BREAK);
        }

        public void printAll(){
            System.out.println(out.toString());
        }
    }
}