#include <bits/stdc++.h>
using namespace std;
void call() {
  int n, m, i, j;
  long long int sum = 0, flag, value, count = 0, max = 0;
  cin >> n >> m;
  int ar[n], br[m];
  for (i = 0; i < n; i++) cin >> ar[i];
  for (i = 0; i < m; i++) cin >> br[i];
  for (i = 0; i < n; i++) {
    sum += ar[i];
    if (max < sum) max = sum;
  }
  for (i = 0; i < m; i++) {
    count = 0;
    if (max < br[i] && sum <= 0)
      cout << "-1 ";
    else {
      if (sum > 0 && br[i] > max) {
        flag = br[i] / sum;
        value = br[i] - (flag - 1) * sum;
        for (j = 0; j < n; j++) {
          value = value - ar[j];
          if (value <= 0) break;
          count++;
        }
        cout << (flag - 1) + (flag - 1) * (n - 1) + count << " ";
      }
      if (br[i] <= max) {
        for (j = 0; j < n; j++) {
          value = br[i];
          value = value - ar[j];
          if (value <= 0) break;
          count++;
        }
        cout << count << " ";
      }
    }
  }
}
int main() {
  int i, t;
  cin >> t;
  i = t;
  while (i > 0) {
    call();
    i--;
    cout << "\n";
  }
  return 0;
}
