#include <bits/stdc++.h>
using namespace std;
int t;
int n, m;
int a[200000], x[200000];
struct node {
  int i;
  int pre;
} pre[200000];
bool cmp(node& n1, node& n2) { return n1.pre < n2.pre; }
bool cmpi(node& n1, node& n2) { return n1.i < n2.i; }
int find(int l, int r, int val) {
  int res = r + 1;
  while (l <= r) {
    int middle = l + ((r - l) >> 1);
    if (pre[middle].pre >= val) {
      r = middle;
      res = min(res, middle);
      if (l == r) break;
    } else if (pre[middle].pre < val) {
      l = middle + 1;
    }
  }
  return res;
}
int main() {
  cin >> t;
  for (int k = 0; k < t; k++) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> x[i];
    }
    pre[0].pre = a[0];
    pre[0].i = 0;
    for (int i = 1; i < n; i++) {
      pre[i].pre = a[i] + pre[i - 1].pre;
      pre[i].i = i;
    }
    sort(pre, pre + n, cmp);
    for (int i = 0; i < m; i++) {
      int res = 0;
      int temp = find(0, n - 1, x[i]);
      if (temp != n) {
        sort(&pre[temp], pre + n, cmpi);
        cout << pre[temp].i << " ";
        continue;
      }
      for (int j = 1; 1; j++) {
        res += n;
        if (j > 2 && x[i] - pre[n - 1].pre >= x[i]) {
          res = -1;
          break;
        }
        x[i] -= pre[n - 1].pre;
        temp = find(0, n - 1, x[i]);
        if (temp != n) {
          sort(&pre[temp], pre + n, cmpi);
          res += pre[temp].i;
          break;
        }
      }
      cout << res << " ";
    }
    cout << endl;
  }
  return 0;
}
