#include <bits/stdc++.h>
using namespace std;
const int N = 2E5 + 10;
int a[N];
long long smax[N];
long long res[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    scanf("%d %d", &n, &m);
    long long sum = 0;
    for (int i = 1; i <= (n); ++i)
      scanf("%d", &a[i]), sum += a[i], smax[i] = max(smax[i - 1], sum);
    for (int i = 1; i <= (m); ++i) {
      int x;
      scanf("%d", &x);
      if (x <= smax[n])
        res[i] = lower_bound(smax + 1, smax + 1 + n, x) - smax;
      else {
        if (sum <= 0)
          res[i] = 0;
        else {
          int temp = x - smax[n];
          if (temp < 0) assert(0);
          int num = (temp + sum - 1) / sum;
          x -= sum * num;
          res[i] =
              1ll * num * n + lower_bound(smax + 1, smax + 1 + n, x) - smax;
        }
      }
    }
    for (int i = 1; i <= (m); ++i) printf("%lld%c", res[i] - 1, " \n"[i == m]);
  }
  return 0;
}
