#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9;
long long a[200005], s[200005], st[200005], id[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    s[0] = 0;
    int cnt = 0, mx = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      s[i] = s[i - 1] + a[i];
      if (a[i] > mx) {
        mx = s[i];
        st[++cnt] = mx;
        id[cnt] = i;
      }
    }
    if (s[n] <= 0) {
      for (int i = 1; i <= m; i++) {
        int x;
        cin >> x;
        if (x > mx)
          cout << "-1 ";
        else {
          int pos = lower_bound(st + 1, st + cnt + 1, x) - st;
          cout << id[pos] - 1 << ' ';
        }
      }
    } else {
      for (int i = 1; i <= m; i++) {
        long long x;
        cin >> x;
        if (x > mx) {
          long long c = (x - mx + s[n] - 1) / s[n];
          x -= c * s[n];
          int pos = lower_bound(st + 1, st + cnt + 1, x) - st;
          cout << c * n + id[pos] - 1 << ' ';
        } else {
          int pos = lower_bound(st + 1, st + cnt + 1, x) - st;
          cout << id[pos] - 1 << ' ';
        }
      }
    }
    cout << "\n";
  }
}
