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

public class Old_Floopy_Drive {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}

	public static void shuffle(int[] a) {
		Random r = new Random();

		for (int i = 0; i <= a.length - 2; i++) {
			int j = i + r.nextInt(a.length - i);

			swap(a, i, j);
		}

		Arrays.sort(a);
	}

	public static void swap(int[] a, int i, int j) {
		int temp = a[i];
		a[i] = a[j];
		a[j] = temp;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader t = new FastReader();
		PrintWriter o = new PrintWriter(System.out);
		int test = t.nextInt();

		while (test-- > 0) {
			int n = t.nextInt();
			int q = t.nextInt();
			long[] a = new long[n];
			long sum = 0;
			long max = 0;
			TreeMap<Long, Integer> map = new TreeMap<>();

			for (int i = 0; i < n; ++i) {
				sum += (a[i] = t.nextLong());
				max = sum > max ? sum : max;

				if (!map.containsKey(sum))
					map.put(sum, i + 1);
			}

			while (q-- > 0) {
				long x = t.nextLong();

				if (sum <= 0 && max < x) {
					o.print("-1 ");
					continue;
				}

				if (max >= x) {
					if (map.containsKey(x)) {
						o.print(map.get(x) - 1 + " ");
					} else {
						o.print(map.get(map.higherKey(x)) - 1 + " ");
					}
				} else {
					long round = x / sum;
					x %= sum;

					if (x == 0)
						o.print(round * n - 1 + " ");
					else if (map.containsKey(x)) {
						o.print(round * n + map.get(x) - 1 + " ");
					} else {
						o.print(round * n + map.get(map.higherKey(x)) - 1 + " ");
					}
				}
			}

			o.println();
		}

		o.flush();
		o.close();
	}
}