#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 200;
int a[N], b[N];
long long sum[N];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    long long mx = -1e18;
    memset(sum, 0, sizeof sum);
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) {
      sum[i] = sum[i - 1] + a[i], mx = max(mx, sum[i]);
    }
    while (m--) {
      long long x, w = 0;
      scanf("%lld", &x);
      if (x > mx) {
        if (sum[n] <= 0) {
          printf("-1 ");
          continue;
        } else {
          w = (x - mx + sum[n] - 1) / sum[n];
          x -= w * sum[n];
        }
      }
      int i;
      for (i = 1; i <= n; i++) {
        if (sum[i] >= x) break;
      }
      printf("%d ", i - 1 + w * n);
    }
    printf("\n");
  }
}
