import java.util.Scanner;

public class OldFloppyDrive {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = Integer.valueOf(sc.nextLine());
        
        for (int i = 0; i < t; ++i) {
            String[] parts = sc.nextLine().split(" ");
            int n = Integer.valueOf(parts[0]);
            int m = Integer.valueOf(parts[1]);
            int[] a = new int[n];

            parts = sc.nextLine().split(" ");
            for (int j = 0; j < n; ++j) {
                a[j] = Integer.valueOf(parts[j]);
            }

            parts = sc.nextLine().split(" ");
            for (int j = 0; j < m; ++j) {
                int x = Integer.valueOf(parts[j]);
                System.out.print(calculate(a, x) + " ");
            }
            System.out.println();
        }
    }

    public static int calculate(int[] a, int x) {
        int n = a.length;
        int max = a[0];
        int[] t = new int[n];
        t[0] = a[0];
        for (int i = 1; i < n; ++i) {
            t[i] = t[i - 1] + a[i];
            if (max < t[i]) max = t[i];
        }

        int add = t[n - 1];
        if (add <= 0 || max >= x) {
            for (int i = 0; i < n; ++i) {
                if (t[i] >= x) {
                    return i;
                }
            }
            return -1;
        }
        
        int i = 0;
        for (int k = (int) 2e9; k > 0; k /= 2) {
            long count = i + k;
            if (count * add + max < x) {
                i += k;
            }
        }
        ++i;

        x -= add * i;
        for (int j = 0; j < n; ++j) {
            if (t[j] >= x) {
                return i * n + j;
            }
        }


        return 0;
    }

}
