#include <bits/stdc++.h>
using namespace std;
const long long MX = 2e5 + 5;
map<long long, long long> mp;
long long t, n, m, x, mx, p, y;
int main() {
  cin >> t;
  while (t--) {
    mp.clear();
    cin >> n >> m;
    p = 0;
    for (long long i = 0; i < n; i++) {
      cin >> x;
      p += x;
      if (!mp.count(p)) mp[p] = i;
    }
    mx = mp.rbegin()->first;
    if (mx < 0) mx = 0;
    while (m--) {
      cin >> x;
      if (x > mx) {
        if (p <= 0)
          cout << -1 << " ";
        else {
          y = (x / p) * n - 1;
          if (x % p) {
            auto it = mp.lower_bound(x % p);
            y += it->second + 1;
          }
          cout << y << " ";
        }
      } else {
        auto it = mp.lower_bound(x);
        y = it->second;
        cout << y << " ";
      }
    }
    cout << "\n";
  }
  return 0;
}
