import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.Iterator;
public class J{
	
	static int ans = 0 ;
	static int num ;
	static Pair [] farr;
	static boolean flag;
	static int n;
	static class Pair implements Comparable <Pair> {
		long x ; 
		 int y ; 
		 public Pair (long x , int y) {
			 this.x  =x ; 
			 this.y = y ; 
		 }
		@Override
		public int compareTo(Pair other) {
			// TODO Auto-generated method stub
			if (this.x != other.x) {
				return Long.compare(this.x, other.x);
			}
			else return Integer.compare(this.y, other.y);
			
			
		}
		public String toString () {
			return "("+ this.x + " " + this.y+ ")" ; 
		}
		
		
	}
	public static int  search (int x) {
		int s = 0 ; int f = n-1 ; 
		while (f >= s  ) {
			int mid = (f+s) / 2  ; 
			if (farr[mid].x >= x) {
				f = mid-1; 
				ans = farr[mid].y; 
				
//				System.out.println(ans);
				flag = true ;
			}else {
				s = mid+1 ; 
				
			}
			if (flag) for (int i = 0 ; i < n ; i ++ ) {
					ans = Math.min(ans, farr[i].y);
				}

		}
		return ans ;
		
		
	}
	
	
	public static void main (String[] args )throws IOException  {
		 Scanner sc =new Scanner (System.in);
		 PrintWriter pw = new PrintWriter(System.out);
		 
		 int t = sc.nextInt();
		while (t-- > 0 ) {
			n = sc.nextInt();
			int m = sc.nextInt();
			int [] arr = new int [n]; 
			int [] xs = new int[m];
//			HashSet <Pair> hs = new HashSet<>();
			farr = new Pair [n];
			long sum = 0 ; 
			for (int i = 0 ; i < n ; i ++ ) {
				arr[i] = sc.nextInt();
				sum += arr[i]; 
				Pair p = new Pair(sum , i ) ;
				farr[i] = p;
				
			}
			
			Arrays.sort(farr);
			for (int j = 0 ; j < m ; j ++ ) {
				xs [j] = sc.nextInt();
				
			} ans = 0  ;
			for (int k = 0 ; k < m ; k ++ ) {
				num = xs[k]; ans = 0 ;
				 flag = false ;
				search(num);
//				pw.println(flag);
				if (flag) pw.print(ans +  " ");
				else {
					if (sum <= 0 ) pw.print(-1 + " " );
					else {
						int sec = (int) (((num / farr[n-1].x) * farr[n-1].y) + search((int)(num%farr[n-1].x) + 1 ));
						pw.print(sec+ " " );
					}
					
					
				}
				
				
				
				
				
			}
			
			
			
//			pw.println(Arrays.toString(farr));
			pw.println();
			
			
			
			
		}
		
	       pw.close();
	}


	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
	}
 
 
}


