#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using Vi  = vector<int>;
using Pii = pair<int,int>;
using Pil = pair<int,ll>;
#define mp make_pair
#define pb push_back
#define x  first
#define y  second
#define rep(i,b,e) for(int i=(b); i<(e); i++)
#define each(a,x)  for(auto& a : (x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int((x).size())
#define tem template<class t,class u,class...w>
#define pri(x,y,z)tem auto operator<<(t&o,u a)->decltype(x,o) { o << z; return o << y; }
pri(a.print(), '}', '{'; a.print())
pri(a.y, ')', '(' << a.x << ", " << a.y)
pri(all(a), ']', '['; auto d=""; for (auto i : a) (o << d << i, d = ", "))
void DD(...) {}
tem void DD(t s, u a, w... k) {
    for (int b=1; *s && *s - b*44; cerr << *s++) b += 2 / (*s*2 - 81);
    cerr << ": " << a << *s++; DD(s, k...);
}
#ifdef LOC
#define deb(...) (DD("[,\b :] "#__VA_ARGS__, __LINE__, __VA_ARGS__), cerr << endl)
#else
#define deb(...)
#endif
#define DBP(...) void print() { DD(#__VA_ARGS__, __VA_ARGS__); }
#define endl '\n'
#define int long long

//type 0 - query id with sum x
//type 1 - pref id with sum x
struct Event {
    int type, id;
    ll x;
    bool operator< (const Event & e) const {
        return Pil(x, type) < Pil(e.x, e.type);
    }
};

void run() {
    int n, m;
    cin >> n >> m;
    ll maxSum = 0;
    vector<ll> pref(n+1);
    vector<ll> res(m, -1);
    vector<Event> events;
    for (int i = 1; i <= n; i++) {
        ll x;
        cin >> x;
        pref[i] = pref[i-1] + x;
        events.push_back({1, i, pref[i]}); 
        maxSum = max(maxSum, pref[i]);
    }
    for (int i = 0; i < m; i++) {
        ll x;
        cin >> x;
        if (pref[n] < 0 && maxSum < x) {
            continue;
        }
        if (pref[n] <= 0) {
            events.push_back({0, i, x});
        } else {
            // while (x > maxSum) {
            //     x -= pref[n];
            //     res[i] += n;
            // }
            if (x > maxSum) {
                ll cycles = (x - maxSum + pref[n] - 1)/ pref[n];
                res[i] += cycles * n;
                x -= cycles * pref[n];
            }
            events.push_back({0, i, x});
        }
    }
    sort(all(events));
    reverse(all(events));
    int minSuf = n;
    for (Event e : events) {
        if (e.type == 0) {
            res[e.id] += minSuf;
        } else {
            minSuf = min(minSuf, e.id);
        }
    }
    for (ll r : res) {
        cout << r << " ";
    }
    cout << endl;
}

main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(10);
    //int t = 1;
    int t; cin >> t;
    while (t--) run();
    return 0;
}