// Nurstan Duisengaliev(REALBOY)
// не, не надо меня узнавать 
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")*/                   
      
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define pll pair <ll, ll>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
#define int ll
using namespace std;
 
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 1;
int a[N], pref[N], maxi[N]; 
void solve () {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		pref[i] = pref[i - 1] + a[i];
	}
	maxi[0] = -mod;	
	for (int i = 1; i <= n; i ++) maxi[i] = max (maxi[i - 1], pref[i]);	
	while (m --) {
		int x;
		cin >> x;
		if (pref[n] <= 0) {
			int l = 1, r = n, o = 0;
			while (l <= r) {
				int mid = l + r >> 1;
				if (maxi[mid] >= x) {
					r = mid - 1;
					o = mid;
				}
				else l = mid + 1;
			}
			cout << o - 1 << " ";		
		}	
		else {
			int l = 0, r = (int)1e9, o = -1;
			while (l <= r) {
				int mid = l + r >> 1;
				if (mid * pref[n] + maxi[n] < x) {
				    o = mid;
					r = mid - 1;	
				}
				else l = mid + 1;
			}
			o ++;
			ll ans = o * n;
			x -= o * pref[n];
			if (x != 0) {
				l = 1, r = n, o = -1;
				while (l <= r) {
					int mid = l + r >> 1;
					if (maxi[mid] >= x) {
						r = mid - 1;
						o = mid;
					}
					else l = mid + 1;
				}
				ans += o;
			}
			cout << ans - 1 << " ";
		}
	}
	cout << '\n';
}   	
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT;
    cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	                                    
}