#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e6 + 10;
struct myComp {
  bool operator()(const pair<long long, long long> &v, const long long &key) {
    return (v.first < key);
  }
  bool operator()(const long long &key, const pair<long long, long long> &v) {
    return (v.first > key);
  }
};
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > p_sum;
  long long sumAll = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    sumAll += x;
    if (p_sum.empty() || sumAll > p_sum.back().first) {
      p_sum.push_back(make_pair(sumAll, i));
    }
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    if (p_sum.back().first < x && sumAll <= 0) {
      cout << -1 << " ";
      continue;
    }
    int round = 0;
    if (p_sum.back().first < x) {
      round = (x - 1) / sumAll;
    }
    x -= round * sumAll;
    auto it = lower_bound((p_sum).begin(), (p_sum).end(), x, myComp()) -
              p_sum.begin();
    cout << round * n + p_sum[it].second << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int tt = 1;
  cin >> tt;
  for (int i = 1; i <= tt; i++) {
    solve();
  }
  return 0;
}
