import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import java.util.StringTokenizer;
import static java.lang.Math.*;

public class G {

	static FastScanner sc;
	static PrintWriter pw;

	public static void main(String[] args) {
		sc = new FastScanner();
		pw = new PrintWriter(System.out);
		int T = sc.nextInt();
		while (T-- > 0) {			
			solve();
		}

		pw.close();
	}


	private static void solve() {
		int n = sc.nextInt();
		long m = sc.nextLong();			
		long[] a = new long[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		for(int i = 0; i < m; i++) {
			long x = sc.nextLong();			
			pw.print(find(x, a)+ " ");
		}
		pw.println();
		
	}
	
	static long find(long x, long[] a) {
		int n = a.length;
		long sum = 0;
		for(int i = 0; i < n; i++) {			
			sum += a[i];
			if(sum >= x) {
				return i;
			}
		}	
		
		if(sum <= 0) {			
			return -1;
		}
		long rounds = x / sum;
		long curr = (rounds - 1)*sum;
		long time = ((rounds - 1)*n) - 1;
		int ind = 0;
		while(curr < x) {
			curr += a[ind];
			ind ++;
			ind -= (ind >= n) ? n : 0;
			time ++;
		}
		return time;
	}
	
	static void debug(Object... O) {
		System.out.println(Arrays.deepToString(O));
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

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

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

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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

}