#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INT_INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const int POS[8] = {0, 1, 0, -1, 1, 0, 1, -1};
const int MAXM = 1000005;
const int MAXN = 200005;
long long a[MAXN], p[MAXN];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    long long Max = -1e18;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      p[i] = p[i - 1] + a[i];
      Max = max(Max, p[i]);
    }
    while (m--) {
      long long x;
      cin >> x;
      long long ans = 0;
      if (x > Max) {
        if (p[n] <= 0) {
          cout << -1 << " ";
          continue;
        }
        int t = (x - Max) / p[n];
        if (Max == p[n]) t++;
        if (t > 0) ans += t * n;
        x -= t * p[n];
      }
      if (x == 0)
        ans--;
      else
        for (int i = 1; i <= n; i++) {
          if (p[i] >= x) {
            ans += i - 1;
            break;
          }
        }
      cout << ans << " ";
    }
    cout << endl;
  }
  return 0;
}
