#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long t;
  cin >> t;
  long long d = 0;
  for (long long test = 0; test < t; test++) {
    long long n, m;
    cin >> n >> m;
    long long a[n], x[m];
    long long pre[n + 1];
    pre[0] = 0;
    long long maxi = 0;
    vector<pair<long long, long long> > v;
    v.push_back({0, 0});
    long long en = 0;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      pre[i + 1] = pre[i] + a[i];
      maxi = max(pre[i + 1], maxi);
      if (pre[i + 1] > v[en].second) {
        v.push_back({pre[i + 1], i + 1});
        en++;
      }
    }
    for (long long i = 0; i < m; i++) {
      d++;
      cin >> x[i];
      if (pre[n] <= 0) {
        if (x[i] <= maxi) {
          pair<long long, long long> temp;
          temp.first = x[i];
          temp.second = -1;
          long long ind = lower_bound(v.begin(), v.end(), temp) - v.begin();
          cout << v[ind].second - 1 << " ";
        } else {
          cout << -1 << " ";
        }
      } else {
        long long times = ceil((double)(x[i] - maxi) / pre[n]);
        if (times <= 0) {
          times = 0;
        }
        long long left = x[i] - pre[n] * times;
        pair<long long, long long> temp;
        temp.first = left;
        temp.second = -1;
        long long ind = lower_bound(v.begin(), v.end(), temp) - v.begin();
        long long res = n * times + v[ind].second;
        if (d == 795) {
          long long p = v.size();
          cout << p << "\n";
        }
        cout << res - 1 << " ";
      }
    }
    cout << "\n";
  }
}
