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

public class OldFloppyDrive {

	// https://codeforces.com/contest/1490/problem/G
	
	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("OldFloppyDrive"));

		int t = Integer.parseInt(in.readLine());
		StringBuilder s =new StringBuilder();
		while (t-- > 0) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			int n = Integer.parseInt(st.nextToken());
			int m = Integer.parseInt(st.nextToken());
			long[] arr = new long[n];
			st = new StringTokenizer(in.readLine());
			for (int i=0; i<n; i++) {
				arr[i] = Integer.parseInt(st.nextToken());
			}
			st = new StringTokenizer(in.readLine());
			long[] x = new long[m];
			for (int i=0; i<m; i++) {
				x[i] = Integer.parseInt(st.nextToken());
			}
			
			long[] psum = new long[n];
			long maxpsum = arr[0];
			for (int i=0; i<n; i++) {
				if (i == 0) psum[i] = arr[i];
				else psum[i] = arr[i] + psum[i-1];
				maxpsum = Math.max(maxpsum, psum[i]);
			}
			
			TreeMap<Long, Integer> psum_map = new TreeMap<>();
			for (int i=0; i<n; i++) {
				if (!psum_map.containsKey(psum[i])) psum_map.put(psum[i], i);
			}
			
			int minindex = n-1;
			for (Long a : psum_map.descendingKeySet()) {
				if (minindex < psum_map.get(a)) {
					psum_map.put(a, minindex);
				}
				else {
					minindex = psum_map.get(a);
				}
			}
			
			for (int j=0; j<m; j++) {
				if (psum[n-1] <= 0) {
					// if tle can use a map and coord compress thingy
					if (maxpsum < x[j]) {
						s.append(-1 + " ");
					}
					else {
						Long a = psum_map.ceilingKey(x[j]);
						s.append(psum_map.get(a) + " ");
//						for (int i=0; i<n; i++) {
//							if (psum[i] >= x[j]) {
//								s.append(i + " ");
//								break;
//							}
//						}
					}
					
				}
				else {
					long min=0;
					long max=x[j];
					while (min<max) {
						long middle = min + (max-min)/2;
						if (check(middle, psum, maxpsum, x[j])) {
							max = middle;
						}
						else min = middle+1;
					}
					long sum = psum[n-1] * min;
					Long a = psum_map.ceilingKey(x[j] - sum);
					s.append(min * n + psum_map.get(a) + " ");
//					for (int i=0; i<n; i++) {
//						if (sum + psum[i] >= x[j]) {
//							s.append(min * n + i + " ");
//							break;
//						}
//					}
				}
			}
			s.append("\n");
		}
		System.out.print(s);
	}
	
	public static boolean check(long mid, long[] psum, long max, long need) {
		return psum[psum.length-1] * mid + max >= need;
	}
}