#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t, n, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<int> a(n), x(m);
    for (int &y : a) cin >> y;
    for (int &y : x) cin >> y;
    vector<long long int> init(n);
    init[0] = a[0];
    for (int i = 1; i < n; i++) init[i] = init[i - 1] + a[i];
    long long int maxi = *max_element(begin(init), end(init));
    vector<long long int> value;
    vector<int> index;
    for (int i = 0; i < n; i++) {
      if (value.empty() || init[i] > value.back()) {
        value.push_back(init[i]);
        index.push_back(i);
      }
    }
    for (int i = 0; i < m; i++) {
      if (maxi < x[i] && init[n - 1] <= 0) {
        cout << "-1 ";
      } else {
        int spin = ceil((x[i] - maxi) / (init[n - 1] * 1.0));
        x[i] -= (spin * init[n - 1]);
        long long int ans =
            spin * 1LL * n +
            index[lower_bound(begin(value), end(value), x[i]) - begin(value)];
        cout << ans << " ";
      }
    }
    cout << "\n";
  }
}
