#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, k, n, m, l, r, x, y, z, p, q, sum, ans, t, a, b, c, d;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    long long arr[n], brr[m];
    for (i = 0; i < n; i++) cin >> arr[i];
    for (i = 0; i < m; i++) cin >> brr[i];
    vector<pair<long long, long long> > vp(n);
    vp[0] = make_pair(arr[0], 0);
    for (i = 1; i < n; i++) vp[i] = make_pair(vp[i - 1].first + arr[i], i);
    sort(vp.begin(), vp.end());
    x = vp[n - 1].first;
    vector<long long> vodd, iodd, veven, ieven;
    for (i = 0; i < n; i++) {
      if (vp[i].first % 2 != 0) {
        vodd.push_back(vp[i].first);
        iodd.push_back(vp[i].second);
      } else {
        veven.push_back(vp[i].first);
        ieven.push_back(vp[i].second);
      }
    }
    for (i = 0; i < m; i++) {
      k = 1;
      y = 0;
      if (k && vodd.size() > 0) {
        j = lower_bound(vodd.begin(), vodd.end(), brr[i]) - vodd.begin();
        if (j == vodd.size()) j--;
        if (x) {
          y = (brr[i] - vodd[j]) / x;
          y = abs(y);
        }
        if (vodd[j] + x * y >= brr[i]) {
          cout << n * y + iodd[j] << " ";
          k = 0;
        }
      }
      if (k && veven.size() > 0) {
        j = lower_bound(veven.begin(), veven.end(), brr[i]) - veven.begin();
        if (j == veven.size()) j--;
        if (x) {
          y = (brr[i] - veven[j]) / x;
          y = abs(y);
        }
        if (veven[j] + x * y >= brr[i]) {
          cout << n * y + ieven[j] << " ";
          k = 0;
        }
      }
      if (k) cout << -1 << " ";
    }
    cout << endl;
  }
  return 0;
}
