#include <bits/stdc++.h>
using namespace std;
vector<int long long> v;
vector<int long long> v1;
map<int long long, int long long> m1;
map<int long long, int long long> m2;
int long long n;
int long long solve(int long long rou, int long long sum, int long long val) {
  int long long total = rou * sum;
  if (total >= val) {
    return -1;
  } else {
    val = val - total;
    vector<int long long>::iterator low1;
    int long long n1 = v.size();
    low1 = lower_bound(v.begin(), v.end(), val);
    int long long ind = (low1 - v.begin());
    if (ind < n1) {
      return m1[v[ind]];
    }
  }
  return n;
}
int main() {
  int long long t;
  int long long m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    int long long sum = 0;
    int long long val;
    for (int i = 0; i < n; i++) {
      cin >> val;
      sum += val;
      if (v.size() == 0) {
        v.push_back(sum);
        m1[sum] = i;
        m2[sum] = 1;
      } else if (sum >= v[v.size() - 1]) {
        v.push_back(sum);
        if (m2[sum] == 0) {
          m1[sum] = i;
          m2[sum] = 1;
        }
      }
    }
    for (int i = 0; i < m; i++) {
      cin >> val;
      int long long l = 0;
      int long long r = 1000000005;
      int long long ans = -1;
      if (val == 0) {
        cout << 0 << ' ';
        continue;
      }
      int flag = 0;
      vector<int long long>::iterator low1;
      int long long n1 = v.size();
      low1 = lower_bound(v.begin(), v.end(), val);
      int long long ind = (low1 - v.begin());
      if (ind < n1) {
        cout << m1[v[ind]] << ' ';
        flag = 1;
        continue;
      }
      if (flag == 0) {
        while (1) {
          if (l > r) {
            break;
          }
          int long long mid = (l + r) / 2;
          if (solve(mid, sum, val) < n) {
            if (ans == -1) {
              ans = mid * n + solve(mid, sum, val);
            } else {
              ans = min(ans, mid * n + solve(mid, sum, val));
            }
            if (sum < 0 && m >= 0) {
              l = mid + 1;
            } else {
              r = mid - 1;
            }
          } else {
            if (sum < 0 && m >= 0) {
              r = mid - 1;
            } else {
              l = mid + 1;
            }
          }
        }
        if (ans > 5000000005) {
          ans = -1;
        }
        cout << ans << ' ';
      }
    }
    cout << '\n';
    v.clear();
    m1.clear();
    m2.clear();
  }
  return 0;
}
