#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  int in;
  int n;
  int m;
  int dif;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<int> a(n);
    vector<int> dp(n);
    for (int& el : a) cin >> el;
    dp[0] = a[0];
    for (int i = 1; i < n; i++) dp[i] = dp[i - 1] + a[i];
    dif = dp[n - 1];
    while (m--) {
      int minans = 1000000000;
      cin >> in;
      for (int i = 0; i < n; i++) {
        if (dif <= 0 && dp[i] >= in) {
          minans = i;
          break;
        }
        if (dif > 0) {
          minans = min(minans, max(in - dp[i] + dif - 1, 0) / dif * n + i);
        }
      }
      if (minans == 1000000000) {
        cout << -1 << ' ';
      } else {
        cout << minans << ' ';
      }
    }
    cout << endl;
  }
}
