import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class F {

    static class Pair {
        long a;
        long b;

        public Pair(long a, long b) {
            this.a = a;
            this.b = b;
        }
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int t = getInt(reader.readLine());
        while (t-- > 0) {
            int[] inp = getArray(reader.readLine());
            int n = inp[0];
            int m = inp[1];
            long[] a = getLongArray(reader.readLine());
            long[] xl = getLongArray(reader.readLine());
            ArrayList<Pair> l = new ArrayList<>();
            long sum = 0;
            for (int i = 0; i < n; i++) {
                sum += a[i];
                l.add(new Pair(sum, i));
            }
            l.sort((a1, b1) -> (int) (a1.a == b1.a ? a1.b - b1.b : a1.a - b1.a));
            for (int j = 0; j < m; j++) {
                long x = xl[j];
                if (sum <= 0) {
                    System.out.print(-1 + " ");
                    continue;
                }
                int r = (int) (x % sum);
                long q = x / sum;
                if (r != 0) {
                    int lower = lowerBound(l, n, r);
                    if (lower < 0) lower = 0;
                    long ans = q * n + l.get(lower).b;
                    System.out.print(ans + " ");
                } else {
                    int lower = lowerBound(l, n, (int) sum);
                    if (lower < 0) lower = 0;
                    long ans = (q - 1) * n + l.get(lower).b;
                    System.out.print(ans + " ");
                }
            }
            System.out.println();
        }
    }

    // Use this instead of Arrays.sort() on an array of ints. Arrays.sort() is n^2
    // worst case since it uses a version of quicksort. Although this would never
    // actually show up in the real world, in codeforce s, people can hack, so
    // this is needed.
    static int[] ruffleSort(int[] a) {
        //ruffle
        int n = a.length;
        Random r = new Random();
        for (int i = 0; i < a.length; i++) {
            int oi = r.nextInt(n), temp = a[i];
            a[i] = a[oi];
            a[oi] = temp;
        }

        //then sort
        Arrays.sort(a);
        return a;
    }


    private static int[] getArray(String readLine) {
        String strings[] = readLine.split(" ");
        int n = strings.length;
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(strings[i]);
        }
        return a;
    }

    private static long[] getLongArray(String readLine) {
        String strings[] = readLine.split(" ");
        int n = strings.length;
        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(strings[i]);
        }
        return a;
    }

    private static int binarySearch(int[] a, int n, int x) {
        int l = 0;
        int r = n - 1;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (a[mid] == x) {
                return mid;
            } else if (a[mid] < x) {
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        return -1;
    }

    private static int upperBound(int[] a, int n, int x) {
        int l = -1; //a[ans] <l
        int r = n; //a[ans]>=r
        while (l + 1 < r) {
            int mid = (l + r) / 2;
            if (a[mid] < x) {
                l = mid;
            } else {
                r = mid;
            }
        }
        return r;
    }

    private static int lowerBound(ArrayList<Pair> a, int n, int x) {
        int l = -1; //a[ans] <l
        int r = n; //a[ans]>=r
        while (l + 1 < r) {
            int mid = (l + r) / 2;
            if (a.get(mid).a <= x) {
                l = mid;
            } else {
                r = mid;
            }
        }
        if (l != -1) {
            while (l > 0 && a.get(l).a == x) l--;
            if (l == 0 && a.get(0).a == x) return l;
            else l++;
        }
        return l;
    }

    private static int getInt(String s) {
        try {
            return Integer.parseInt(s);
        } catch (Exception e) {
            return 0;
        }
    }

    private static long getLong(String s) {
        try {
            return Long.parseLong(s);
        } catch (Exception e) {
            return 0;
        }
    }
}
