#include <bits/stdc++.h>
using namespace std;
long long int fact[200005];
long long int fact_(long long int n) {
  long long int ans = 1;
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= n; i++) {
    ans = (ans * i) % 1000000007;
    fact[i] = ans % 1000000007;
  }
  return ans;
}
long long int mod_inv(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b % 2 == 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b = b >> 1;
  }
  return ans;
}
long long int ncr(long long int n, long long int r) {
  if (n == 0 && r == 0) return 1;
  if (n < r) return 0;
  if (r == 0) return 1;
  if (r == 1) return n;
  if (n == r) return 1;
  return ((((fact[n] % 1000000007) *
            mod_inv(fact[r] % 1000000007, 1000000007 - 2)) %
           1000000007) *
          mod_inv(fact[n - r] % 1000000007, 1000000007 - 2)) %
         1000000007;
}
void solve() {}
bool visited[200005];
void solvet() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    long long int ar[n + 5];
    long long int prefix[n + 5];
    long long int max_sum = -1000000000000000000;
    bool neg_arr = false;
    long long int total_sum;
    prefix[0] = 0;
    for (int i = 1; i <= n; i++) {
      cin >> ar[i];
      prefix[i] = prefix[i - 1] + ar[i];
      max_sum = max(prefix[i], max_sum);
    }
    total_sum = prefix[n];
    if (prefix[n] <= 0) {
      neg_arr = true;
    }
    vector<long long int> sum;
    sum.push_back(prefix[1]);
    for (int i = 2; i <= n; i++) {
      if (prefix[i] > sum.back()) {
        sum.push_back(prefix[i]);
      }
    }
    long long int x;
    for (int i = 0; i < m; i++) {
      cin >> x;
      if (x == sum.front()) {
        cout << "0 ";
        continue;
      }
      if (x > sum.back() && neg_arr) {
        cout << "-1 ";
        continue;
      }
      long long int moves = 0;
      moves += (n) * (x / sum.back());
      x -= (x / sum.back()) * sum.back();
      if (x > 0) {
        long long int temp =
            lower_bound(sum.begin(), sum.end(), x) - sum.begin();
        moves += temp;
      }
      if (x == 0) {
        moves--;
      }
      cout << moves << " ";
    }
    cout << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solvet();
}
