#include <bits/stdc++.h>
void getResult(std::vector<long> disk, std::vector<long> sums) {
  long diskSum = accumulate(disk.begin(), disk.end(), 0);
  for (long threshold : sums) {
    long time = 0;
    long sum = 0;
    unsigned int counter = 0;
    if (diskSum <= 0 && threshold > 0) {
      std::cout << "-1 ";
      continue;
    }
    if ((threshold - sum) / diskSum > 0) {
      int rotations = (threshold - sum) / diskSum;
      sum += diskSum * rotations;
      time += rotations * disk.size();
    }
    while (sum < threshold) {
      sum += disk.at(counter++);
      time++;
      if (counter >= disk.size()) counter = 0;
    }
    std::cout << --time << " ";
  }
}
int main() {
  unsigned int tests;
  std::cin >> tests;
  while (tests-- > 0) {
    unsigned int diskCount, questionCount;
    std::cin >> diskCount >> questionCount;
    std::vector<long> disk;
    std::vector<long> sums;
    disk.reserve(diskCount);
    sums.reserve(questionCount);
    static long input;
    for (unsigned int i = 0; i < diskCount; i++) {
      std::cin >> input;
      disk.push_back(input);
    }
    for (unsigned int i = 0; i < questionCount; i++) {
      std::cin >> input;
      sums.push_back(input);
    }
    getResult(disk, sums);
    std::cout << "\n";
  }
  return 0;
}
