#include <bits/stdc++.h>
using namespace std;
#define float double
#define nn 100
#define mod 1000000007
#define int long long
bool comp(pair<int, int> a, pair<int, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }
    return a.second > b.second;
}
main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        int arr[n];
        int i;
        for (i = 0; i < n; i++) {
            cin >> arr[i];
        }
        int pre[n];
        pre[0] = arr[0];
        for (i = 1; i < n; i++) {
            pre[i] = arr[i] + pre[i - 1];
        }
        vector<pair<int, int>> v1;
        for (i = 0; i < n; i++) {
            v1.push_back({pre[i], i});
        }
        sort(v1.begin(), v1.end());
        for (i = 0; i < n; i++) {
            //cout << v1[i].first << " " << v1[i].second << endl;
        }
        int ad = pre[n - 1];
        int maxx = v1[n - 1].first;
        int j;
        int arr2[m];
        int cnta[m];
        int ans[m] = {0};
        //cout << "ad " << ad << " " << maxx << endl;
        for (j = 0; j < m; j++) {
            int x;
            cin >> x;
            int cnt = 0;
            if (x > maxx) {
                if (ad <= 0) {
                    // //cout << "-1\n";
                    ans[j] = -1;
                    continue;
                }
                cnt = (x - maxx) / ad;
                if ((x - maxx) % ad != 0) {
                    cnt++;
                }
                x -= cnt * maxx;
            }
            arr2[j] = x;
            cnta[j] = cnt;
        }
        v1.clear();
        for (i = 0; i < m; i++) {
            v1.push_back({arr2[i], i});
        }
        sort(v1.begin(), v1.end());
        for (i = 0; i < n; i++) {
            //cout << v1[i].first << " " << v1[i].second << endl;
        }
        j = 0;
        for (i = 0; i < n; i++) {
            for (; j < m; j++) {
                if (ans[v1[j].second] == -1) {
                    continue;
                }
                if (v1[j].first > pre[i]) {
                    break;
                }
                //cout<<"R"<<v1[j].first<<" "<<pre[i]<<" ";
                ans[v1[j].second] = cnta[v1[j].second] * n + i;
            }
            if (j == m) {
                break;
            }
        }
        for (i = 0; i < m; i++) {
            cout << ans[i] << " ";
        }
        cout << endl;
    }
}