#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, int> > pos;
long long a[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  int total = 0;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int ori = m;
    pos.clear();
    long long cur = 0;
    long long mx = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      cur = cur + a[i];
      if (cur > mx) {
        mx = cur;
        pos.push_back(pair<long long, int>(cur, i));
      }
    }
    sort(pos.begin(), pos.end());
    while (m--) {
      total++;
      long long need;
      cin >> need;
      if (total == 272) {
        for (int i = 1; i <= n; i++) cout << a[2] << ' ';
      }
      if (cur <= 0 || need <= mx) {
        if (need > mx)
          cout << -1 << ' ';
        else {
          int l = 0, r = pos.size() - 1;
          while (l < r) {
            int mid = (l + r) / 2;
            if (pos[mid].first >= need)
              r = mid;
            else
              l = mid + 1;
          }
          cout << pos[l].second - 1 << ' ';
        }
      } else {
        long long roll = need / cur;
        need -= cur * roll;
        if (need == 0) {
          need += cur;
          roll--;
        }
        long long ans = 0;
        if (need > 0) {
          int l = 0, r = pos.size() - 1;
          while (l < r) {
            int mid = (l + r) / 2;
            if (pos[mid].first >= need)
              r = mid;
            else
              l = mid + 1;
          }
          ans = roll * n + pos[l].second - 1;
        } else
          ans = roll * n - 1;
        cout << ans << ' ';
      }
    }
    cout << endl;
  }
}
