#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  unsigned short t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    long long data[n];
    for (int x = 0; x < n; x++) {
      cin >> data[x];
    }
    long long query[m];
    for (int x = 0; x < m; x++) {
      cin >> query[x];
    }
    vector<pair<long long, long long>> prefix;
    long long mx = -1e18, sum = 0;
    for (int x = 0; x < n; x++) {
      sum += data[x];
      prefix.push_back({sum, x});
      mx = max(mx, sum);
    }
    sort(prefix.begin(), prefix.end());
    for (int x = 0; x < m; x++) {
      long long best = 1e18;
      if (sum <= 0 && query[x] > mx) {
        best = -1;
      } else {
        long long tmp = (sum == 0 ? 0 : query[x] / sum);
        if (sum == 0 && query[x] == sum) {
          best = min(best, n * 1ll - 1);
        } else if ((sum != 0 && query[x] % sum == 0)) {
          best = min(best, tmp * n - 1);
        } else {
          pair<long long, long long> tmp2 = {query[x] - tmp * sum, -1ll};
          pair<long long, long long> p =
              *lower_bound(prefix.begin(), prefix.end(), tmp2);
          best = min(best, tmp * n + p.second);
        }
      }
      query[x] = best;
    }
    for (int x = 0; x < m; x++) {
      if (x > 0) cout << " ";
      cout << query[x];
    }
    cout << "\n";
  }
  return 0;
}
