#include <bits/stdc++.h>
using namespace std;
inline int read(void) {
  int sum = 0, sign = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return sum * sign;
}
const int maxn = 2e5 + 5;
int a[maxn], b[maxn];
long long s[maxn], mxx;
int main() {
  int t = read();
  while (t--) {
    int n = read(), m = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    for (int j = 1; j <= m; j++) b[j] = read();
    mxx = -2147483648;
    vector<long long> vec;
    map<long long, int> mp;
    for (int i = 1; i <= n; i++) {
      s[i] = s[i - 1] + a[i];
      if (s[i] > mxx) {
        vec.push_back(s[i]);
        mp[s[i]] = i;
      }
      mxx = max(mxx, s[i]);
    }
    for (int i = 1; i <= m; i++) {
      int ans = 0;
      if (1ll * b[i] > mxx) {
        if (s[n] <= 0) {
          cout << "-1 ";
          continue;
        }
        ans += (b[i] - mxx + s[n] - 1) / s[n] * n;
        b[i] -= (b[i] - mxx + s[n] - 1) / s[n] * s[n];
      }
      vector<long long>::iterator p = lower_bound(vec.begin(), vec.end(), b[i]);
      ans += mp[*p] - 1;
      cout << ans << ' ';
    }
    cout << endl;
  }
  return 0;
}
