import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Khater
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        GOldFloppyDrive solver = new GOldFloppyDrive();
        solver.solve(1, in, out);
        out.close();
    }

    static class GOldFloppyDrive {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int t = 1;
            t = sc.nextInt();
            while (t-- > 0) {
                int n = sc.nextInt();
                int m = sc.nextInt();
                int[] arr = sc.nextIntArr(n);
                int[] x = sc.nextIntArr(m);
                long sum = 0;
                long max = Long.MIN_VALUE;
                TreeSet<pair> ts = new TreeSet<>();
                ts.add(new pair(0, -1));
                for (int i = 0; i < n; i++) {
                    sum += arr[i];
                    max = Math.max(max, sum);
                    ts.add(new pair(sum, i));
                }
                for (int i = 0; i < m; i++) {
                    if (ts.ceiling(new pair(x[i], -2)) != null) {
                        pw.print(ts.ceiling(new pair(x[i], -2)).i + " ");
                    } else {
                        if (sum <= 0) pw.print(-1 + " ");
                        else {
                            long rem = max > 0 ? x[i] - max : x[i];
                            long times = (rem + sum - 1) / sum;
                            long need = x[i] - times * sum;
                            if (need <= 0) {
                                need += sum;
                                times--;
                            }
                            if (ts.ceiling(new pair(need, -2)) != null) {
                                pw.print(times * n + (ts.ceiling(new pair(need, -2)).i) + " ");
                            } else pw.print(-1 + " ");
                        }
                    }
                }
                pw.println();
            }

        }

        public class pair implements Comparable<pair> {
            long a;
            int i;

            public pair(long a, int i) {
                this.a = a;
                this.i = i;
            }

            public int compareTo(pair o) {
                return a != o.a ? Long.compare(a, o.a) : i - o.i;
            }

            public String toString() {
                return a + " " + i;
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

        public int[] nextIntArr(int n) {
            try {
                int[] a = new int[n];
                for (int i = 0; i < n; i++)
                    a[i] = nextInt();
                return a;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        }

    }
}

