#include <bits/stdc++.h>
using namespace std;
long long mod = pow(10, 9) + 7;
int gcdExtended(int a, int b, int *x, int *y);
int modInverse(int b, int m) {
  int x, y;
  int g = gcdExtended(b, m, &x, &y);
  if (g != 1) return -1;
  return (x % m + m) % m;
}
int gcdExtended(int a, int b, int *x, int *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
string decimalToBinary(int n) {
  string s = bitset<64>(n).to_string();
  const auto loc1 = s.find('1');
  if (loc1 != string::npos) return s.substr(loc1);
  return "0";
}
int binaryToDecimal(int n) {
  int num = n;
  int dec_value = 0;
  int base = 1;
  int temp = num;
  while (temp) {
    int last_digit = temp % 10;
    temp = temp / 10;
    dec_value += last_digit * base;
    base = base * 2;
  }
  return dec_value;
}
unsigned long long sumbincoef(int N, int k) {
  unsigned long long bincoef = 1, sum = 1;
  int i;
  for (i = 1; i < k; ++i) {
    bincoef = (bincoef * (N - i + 1) / i);
    sum += bincoef;
  }
  return sum;
}
bool is_prime(long long n) {
  if (n == 1) {
    return false;
  }
  long long i = 2;
  while (i * i <= n) {
    if (n % i == 0) {
      return false;
    }
    i += 1;
  }
  return true;
}
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int nCrModp(int n, int r, int p) {
  if (r > n - r) r = n - r;
  int C[r + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p;
  }
  return C[r];
}
bool is_palindrome(string s) {
  int n = s.size();
  for (int i = 0; i < (int)n / 2; i++) {
    if (s[i] == s[n - 1 - i]) {
    } else {
      return false;
    }
  }
  return true;
}
const int N = 200000 + 10;
long long factorialNumInverse[N + 1];
long long naturalNumInverse[N + 1];
long long fact[N + 1];
void InverseofNumber(long long p) {
  naturalNumInverse[0] = naturalNumInverse[1] = 1;
  for (int i = 2; i <= N; i++)
    naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
void InverseofFactorial(long long p) {
  factorialNumInverse[0] = factorialNumInverse[1] = 1;
  for (int i = 2; i <= N; i++)
    factorialNumInverse[i] =
        (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}
void factorial(long long p) {
  fact[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = (fact[i - 1] * i) % p;
  }
}
long long Binomial(long long N, long long R, long long p) {
  long long ans =
      ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  mt19937 rng(
      (unsigned int)chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
  cin >> t;
  int j = t;
  int id = 0;
  while (t > 0) {
    long long n, m;
    cin >> n >> m;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<long long> b(a);
    for (int i = 1; i < n; i++) {
      b[i] += b[i - 1];
    }
    long long maxi = *max_element(b.begin(), b.end());
    long long sum = b[n - 1];
    for (int i = 1; i < n; i++) {
      if (b[i] < b[i - 1]) {
        b[i] = b[i - 1];
      }
    }
    while (m > 0) {
      long long x;
      cin >> x;
      if (sum <= 0) {
        if (x > maxi) {
          cout << -1 << " ";
          id++;
        } else {
          auto it = lower_bound(b.begin(), b.end(), x);
          cout << it - b.begin() << " ";
          id++;
        }
      } else {
        long long val = max((x - maxi) / sum, (long long)0);
        long long secs = val * (n);
        x -= val * sum;
        auto it = lower_bound(b.begin(), b.end(), x);
        if (it != b.end())
          cout << secs + it - b.begin() << " ";
        else {
          while (1) {
            x -= sum;
            secs += n;
            it = lower_bound(b.begin(), b.end(), x);
            if (it != b.end()) {
              break;
            }
          }
          long long val = it - b.begin();
          if (id == 62263 && j == 200) {
            cout << secs << endl;
          }
          cout << (long long)secs + val << " ";
        }
        id++;
      }
      m--;
    }
    cout << endl;
    t--;
  }
}
