#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int T, n, m;
int a[1000010], b[1000010];
long long sum[1000010];
long long st[1000010][30];
void ST() {
  for (int i = 1; i <= n; ++i) st[i][0] = sum[i];
  for (int j = 1; j <= log2(n); ++j) {
    for (int i = 1; i <= n - (1 << j) + 1; ++i)
      st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
  }
}
int RMQ(int l, int r) {
  int len = r - l + 1;
  int t = log2(len);
  return max(st[l][t], st[r - (1 << t) + 1][t]);
}
bool check(int pos, int num) { return RMQ(1, pos) >= num; }
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
      sum[i] = sum[i - 1] + a[i];
    }
    ST();
    for (int i = 1; i <= m; ++i) {
      scanf("%d", &b[i]);
    }
    long long maxx = -1e17;
    for (int i = 1; i <= n; ++i) {
      maxx = max(maxx, sum[i]);
    }
    for (int i = 1; i <= m; ++i) {
      if (sum[n] <= 0) {
        int l = 1, r = n, pos = -1;
        while (l <= r) {
          int mid = (l + r) >> 1;
          if (check(mid, b[i])) {
            pos = mid;
            r = mid - 1;
          } else {
            l = mid + 1;
          }
        }
        if (pos == -1) {
          printf("-1 ");
        } else {
          printf("%d ", pos - 1);
        }
      } else {
        int l = 0, r = 1e9, pos = -1;
        while (l <= r) {
          long long mid = (l + r) >> 1;
          if (mid * sum[n] + maxx >= b[i]) {
            pos = mid;
            r = mid - 1;
          } else {
            l = mid + 1;
          }
        }
        l = 1, r = n;
        int pos2 = -1;
        while (l <= r) {
          int mid = (l + r) >> 1;
          if (check(mid, b[i] - pos * sum[n])) {
            pos2 = mid;
            r = mid - 1;
          } else {
            l = mid + 1;
          }
        }
        printf("%lld ", pos * n + pos2 - 1);
      }
    }
    printf("\n");
  }
  return 0;
}
