#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int N, M;
    cin >> N >> M;
    vector<int> arr(N, 0);
    int sum = 0;
    int pre = 0;
    for (int i = 0; i < N; i++) {
      cin >> arr[i];
      pre = pre + arr[i];
      sum = max(sum, pre);
    }
    vector<pair<int, int>> temp;
    int s = 0;
    for (int i = 0; i < N; i++) {
      s = s + arr[i];
      temp.push_back(make_pair(s, i + 1));
    }
    sort(temp.begin(), temp.end());
    int minT = 1e9;
    for (int i = temp.size() - 1; i >= 0; i--) {
      minT = min(temp[i].second, minT);
      temp[i].second = minT;
    }
    for (int i = 0; i < M; i++) {
      int X;
      cin >> X;
      if (X > sum && pre <= 0) {
        cout << -1 << " ";
        continue;
      }
      int ans = 0;
      int cycles = 0;
      if (pre > 0 && X > sum) cycles = ceil((1.0 * (X - sum)) / pre);
      if (pre > 0 && X > sum) ans = ans + max(0, cycles) * N;
      if (pre > 0 && X > sum) X = X - max(0, cycles) * pre;
      if (X == 0) {
        cout << ans - 1 << " ";
        continue;
      }
      int low = 0;
      int high = temp.size() - 1;
      int ans1 = 1e9;
      while (low <= high) {
        int mid = (low + high) / 2;
        if (temp[mid].first >= X) {
          high = mid - 1;
          ans1 = min(ans1, temp[mid].second);
        } else {
          low = mid + 1;
        }
      }
      cout << ans + ans1 - 1 << " ";
    }
    cout << endl;
  }
  return 0;
}
