#include <bits/stdc++.h>
int main() {
  int t;
  std::cin >> t;
  for (int _ = 0; _ != t; ++_) {
    int n, x;
    std::cin >> n >> x;
    int array[n];
    for (auto& x : array) std::cin >> x;
    long long soma = 0, apice = 0;
    std::map<long long, int> mapa;
    for (int i = 0; i != n; ++i) {
      soma += array[i];
      if (apice < soma && mapa.find(soma) == mapa.end()) mapa[soma] = i;
      apice = std::max(soma, apice);
    }
    std::vector<std::pair<long long, int> > valores;
    for (auto& x : mapa) {
      valores.push_back(x);
    }
    for (int i = 0; i != x; ++i) {
      long long a;
      std::cin >> a;
      if (a <= apice) {
        int l = 0, r = valores.size();
        while (l < r) {
          int m = (l + r) / 2;
          if (valores[m].first >= a) {
            r = m;
          } else {
            l = m + 1;
          }
        }
        printf("%d ", valores[l].second);
        continue;
      }
      if (soma <= 0) {
        printf("-1 ");
        continue;
      }
      long long c = a % (soma);
      long long voltas = (a - c) / soma;
      if (!c) {
        voltas--;
        c += soma;
      }
      int l = 0, r = valores.size();
      while (l < r) {
        int m = (l + r) / 2;
        if (valores[m].first >= c) {
          r = m;
        } else {
          l = m + 1;
        }
      }
      std::cout << ((a - valores[l].first) / soma) * n + (valores[l].second)
                << " ";
    }
    std::cout << std::endl;
  }
}
