import java.io.*;
import java.util.*;
public class A {
    static FastScanner fs;
    public static void main(String[] args) {
        fs=new FastScanner();
        int t = fs.nextInt();
        while (t-->0)
            solve();
    }
    public static void solve() {
        int n = fs.nextInt();
        int m = fs.nextInt();
        int[] a = fs.readArray(n);
        ArrayList<pair> ms = new ArrayList<>();
        int[] xi = fs.readArray(m);
        long maxa = Integer.MIN_VALUE;
        long suma = 0;
        for (int i=0; i<n; i++) {
            suma+=a[i];
            if (suma>maxa) {
                maxa = suma;
                ms.add(new pair(maxa, i));
            }
        }
        for (int x : xi) {
            long first = n*(long)Math.ceil((double)(x-maxa)/suma);
            if (suma<0 && x>maxa) {
                System.out.print(-1+" ");
                continue;
            }
            long now = suma*(long)Math.ceil((double)(x-maxa)/suma);
            long diff = x-now;
            int low = 0;
            int high = ms.size()-1;
            while (low!=high) {
                int mid = (low+high)/2;
                if (ms.get(mid).v>=diff) high = mid;
                else low = mid+1;
            }
            System.out.print(ms.get(low).i+first+" ");
        }
        System.out.println();
    }
    static class pair {
        long v, i;
        pair(long a, long b) {
            v=a; i=b;
        }
    }
    static void ruffleSort(int[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n), temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }
    static final Random random=new Random();
    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());
        }
    }

    static int[] reverse(int[] a) {
        int n=a.length;
        int[] res=new int[n];
        for (int i=0; i<n; i++) res[i]=a[n-1-i];
        return res;
    }
}