#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long modify(long long n) {
  long long res = n;
  res %= 1000000007;
  res += 1000000007;
  res %= 1000000007;
  return res;
}
long long md(long long n) {
  if (n > 0)
    return n;
  else
    return -n;
}
void see(vector<long long> v) {
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
}
long long mv(vector<long long> v) {
  long long m = v[0];
  for (int i = 0; i < v.size(); i++) {
    m = max(v[i], m);
  }
  return m;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> v(n);
  long long x;
  for (int i = 0; i < n; i++) cin >> v[i];
  long long temp = 0;
  for (int i = 0; i < n; i++) temp += v[i];
  for (int i = 0; i < m; i++) {
    cin >> x;
    long long s = 0;
    long long flag = 0;
    for (int j = 0; j < n; j++) {
      s += v[j];
      if (s >= x) {
        cout << j << " ";
        flag = 1;
        break;
      }
    }
    if (flag) continue;
    if (temp <= 0) {
      long long s = 0;
      long long flag = 0;
      for (int j = 0; j < n; j++) {
        s += v[j];
        if (s >= x) {
          cout << j << " ";
          flag = 1;
          break;
        }
      }
      if (flag == 0) cout << "-1 ";
      continue;
    }
    long long time = x / temp;
    time -= 10;
    time = max(time, 0ll);
    long long a = time * temp;
    long long b = time * n - 1;
    long long i1 = 0;
    while (a < x) {
      a += v[i1];
      i1++;
      b++;
      i1 = i1 % n;
      if (a >= x) {
        cout << b << " ";
        break;
      }
    }
  }
  cout << "\n";
}
int main() {
  int t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
