#include <bits/stdc++.h>
using namespace std;
long long a[200030];
long long b[200030];
long long bb[200030];
map<long long, long long> ans;
map<long long, bool> ok;
long long sm;
bool cm(long long x, long long y) { return x % sm < y % sm; }
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long tc;
  cin >> tc;
  while (tc--) {
    long long n, m;
    cin >> n >> m;
    ans.clear();
    ok.clear();
    long long sum = 0;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    for (long long i = 0; i < m; i++) {
      cin >> b[i];
      bb[i] = b[i];
    }
    if (sum <= 0) {
      sort(b, b + m);
      sum = a[0];
      for (long long i = 0, j = 0; i < n && j < m;) {
        if (sum >= b[j]) {
          ans[b[j]] += i;
          ok[b[j]] = 1;
          j++;
        } else {
          i++;
          sum += a[i];
        }
      }
    } else {
      for (long long i = 0; i < m; i++) {
        ans[b[i]] = ((b[i] / sum)) * n;
      }
      sm = sum;
      sort(b, b + m, cm);
      sum = a[0];
      for (long long i = 0, j = 0; i < n && j < m;) {
        if (j != 0) {
          while (b[j] == b[j - 1] && j < m) j++;
        }
        if (j == m) break;
        if (sum >= b[j] % sm) {
          if (b[j] % sm == 0) ans[b[j]]--;
          ans[b[j]] += i;
          ok[b[j]] = 1;
          j++;
        } else {
          i++;
          sum += a[i];
        }
      }
    }
    for (long long i = 0; i < m; i++) {
      if (ok[bb[i]]) {
        cout << ans[bb[i]];
      } else
        cout << -1;
      cout << " ";
    }
    cout << '\n';
  }
  return 0;
}
