#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  for (int yy = 0; yy <= tt - 1; yy++) {
    int n, m;
    cin >> n >> m;
    vector<int> arr(n);
    int sum = 0;
    for (int i = 0; i <= n - 1; i++) {
      cin >> arr[i];
      sum += arr[i];
    }
    vector<int> query(m);
    for (int i = 0; i <= m - 1; i++) {
      cin >> query[i];
    }
    vector<int> pre_sum(n);
    int val = 0;
    int pre_sum_max = 0;
    for (int i = 0; i <= n - 1; i++) {
      val += arr[i];
      pre_sum[i] = val;
      pre_sum_max = max(pre_sum_max, pre_sum[i]);
    }
    vector<int> pre_inc;
    vector<int> pre_index;
    int lead = pre_sum[0];
    pre_inc.push_back(lead);
    pre_index.push_back(0);
    for (int i = 0; i <= n - 1; i++) {
      if (pre_sum[i] > lead) {
        lead = pre_sum[i];
        pre_inc.push_back(lead);
        pre_index.push_back(i);
      }
    }
    for (int i = 0; i <= m - 1; i++) {
      if ((query[i] > pre_sum_max) && (sum <= 0)) {
        cout << "-1 ";
      } else {
        int min_round = 0;
        if (query[i] > pre_sum_max) {
          min_round = (query[i] - pre_sum_max) / sum;
        }
        int rem = query[i] - (min_round * sum);
        auto it = lower_bound(pre_inc.begin(), pre_inc.end(), rem);
        int dval = distance(pre_inc.begin(), it);
        int ans = n * min_round;
        if (dval == (int)pre_index.size()) {
          if (ans == 0) {
            ans += *pre_index.rbegin();
          } else {
            ans += *pre_index.rbegin() + 1;
          }
        } else {
          ans += pre_index[dval];
        }
        cout << ans << " ";
      }
    }
    cout << endl;
  }
  return 0;
}
