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 long calculate(int[] a, int x) {
        int n = a.length;
        int all = 0;
        long[] sums  = new long[n];
        int[] indices = new int[n];
        int end = -1;
        for (int i = 0; i < n; ++i) {
            all += a[i];
            if (end == -1 || all > sums[end]) {
                sums[++end] = all;
                indices[end] = i;
            }
        }

        if (all <= 0 && sums[end] < x) {
            return -1;
        }

        if (sums[end] >= x) {
            for (int i = 0; i <= end; ++i) {
                if (sums[i] >= x) {
                    return indices[i];
                }
            }
        }
        
        long times = (x - sums[end] + all - 1) / all;
        x -= all * times;
        int k = 0;
        int b = end;

        while (b > 0) {
            if (k + b > end || indices[k + b] > x) {
                b /= 2;
            } else {
                k += b;
            }
        }
        return times*n + indices[k];
    }

}
