#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, m, i, j, mi = 1000000001, ma = -1000000001;
    cin >> n >> m;
    vector<long long> v, a;
    for (i = 0; i < n; i++) {
      cin >> j;
      v.push_back(j);
      if (!i)
        a.push_back(j);
      else
        a.push_back(j + a[i - 1]);
      mi = min(mi, a[i]);
      ma = max(ma, a[i]);
    }
    while (m--) {
      long long x, k;
      cin >> x;
      if ((a[n - 1] > 0 && x < mi) || (a[n - 1] < 0 && x > ma) || (!a[n - 1])) {
        for (i = 0; i < n && a[i] < x; i++)
          ;
        if (i < n)
          j = i;
        else
          j = -1;
      } else {
        j = 1000000001;
        for (i = 0; i < n; i++) {
          k = (x - a[i]) / a[n - 1] + ((x - a[i]) % a[n - 1] != 0);
          j = min(j, k * n + i);
        }
      }
      cout << j << ' ';
    }
    cout << '\n';
  }
  return 0;
}
