#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int a[1000];
int board[9][9];
int board2[9][9];
void solve() {
  int n, m;
  cin >> n >> m;
  long long a[n];
  long long sum[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      sum[i] = a[i];
    else
      sum[i] = sum[i - 1] + a[i];
  }
  for (int i = 1; i < n; i++) {
    if (sum[i - 1] > sum[i]) sum[i] = sum[i - 1];
  }
  for (int i = 0; i < m; i++) {
    long long x;
    cin >> x;
    if (x > sum[n - 1] && sum[n - 1] <= 0)
      cout << -1 << " ";
    else {
      long long ans = (x / sum[n - 1]) * n;
      if (ans * sum[n - 1] == x * n) ans--;
      x -= ans * sum[n - 1];
      if (x > 0) {
        int z = lower_bound(sum, sum + n, x) - sum;
        ans += z;
      }
      cout << ans << " ";
    }
  }
  cout << endl;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    solve();
  }
}
