#include <bits/stdc++.h>
using namespace std;
long long sum[200005], x[200005], a[200005];
pair<long long, long long> max1[200005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      sum[i] = sum[i - 1] + a[i];
    }
    for (int i = 1; i <= m; i++) cin >> x[i];
    long long cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (sum[i] > max1[cnt].first) {
        max1[++cnt].first = sum[i];
        max1[cnt].second = i;
      }
    }
    for (int i = 1; i <= m; i++) {
      long long sum1 = 0;
      if (sum[n] <= 0 && max1[cnt].first < x[i])
        cout << -1 << " ";
      else if (max1[cnt].first >= x[i]) {
        long long l = 1, r = cnt;
        while (l < r) {
          long long mid = l + r >> 1;
          if (max1[mid].first < x[i])
            l = mid + 1;
          else
            r = mid;
        }
        cout << max1[l].second - 1 << " ";
      } else {
        int q = ((x[i] + sum[n] - 1) / sum[n] - 1);
        sum1 += q * n;
        sum1--;
        long long k = x[i] - (sum[n] * q);
        long long l = 0, r = cnt;
        while (l < r) {
          long long mid = l + r >> 1;
          if (max1[mid].first < k)
            l = mid + 1;
          else
            r = mid;
        }
        sum1 += max1[l].second;
        cout << sum1 << " ";
      }
    }
    cout << endl;
  }
  return 0;
}
