#include <bits/stdc++.h>
using namespace std;
int find_minimum_stop(vector<int> array, int element, int start, int end) {
  int mid = (start + end) / 2;
  if (start == end) {
    return 0;
  }
  if (element == array[mid]) {
    return mid;
  }
  if (element <= array[mid + 1] && element > array[mid]) {
    return mid + 1;
  } else if (element > array[mid + 1]) {
    return find_minimum_stop(array, element, mid + 1, end);
  } else if (element < array[mid]) {
    return find_minimum_stop(array, element, start, mid);
  }
  return 0;
}
int main() {
  int in_amount;
  string* final_output;
  cin >> in_amount;
  final_output = new string[in_amount];
  for (int i = 0; i < in_amount; i++) {
    unordered_map<int, int> index_saver = {};
    unsigned int n, m;
    int* sum_arr;
    int* questions;
    scanf("%i %i", &n, &m);
    sum_arr = new int[n];
    questions = new int[m];
    for (int j = 0; j < n; j++) {
      fscanf(stdin, "%i", &sum_arr[j]);
    }
    for (int k = 0; k < m; k++) {
      fscanf(stdin, "%i", &questions[k]);
    }
    int acc_sum = 0;
    int biggest_num = 0;
    index_saver[-1] = -1;
    vector<int> check_arr;
    for (int l = 0; l < n; l++) {
      acc_sum += sum_arr[l];
      sum_arr[l] = acc_sum;
      if (acc_sum > biggest_num) {
        index_saver[sum_arr[l]] = l;
        biggest_num = acc_sum;
        check_arr.push_back(sum_arr[l]);
      }
    }
    int diff = sum_arr[n - 1];
    vector<long long int> out_arr;
    if (diff <= 0) {
      for (int o = 0; o < m; o++) {
        if (questions[o] > biggest_num) {
          out_arr.push_back(-1);
        } else {
          int min_index = index_saver[check_arr[find_minimum_stop(
              check_arr, questions[o], 0, check_arr.size() - 1)]];
          out_arr.push_back((long long int)min_index);
        }
      }
    } else {
      for (int p = 0; p < m; p++) {
        unsigned int cycles;
        if (questions[p] <= biggest_num) {
          cycles = 0;
        } else {
          float fcycle = (float)(questions[p] - biggest_num) / (float)diff;
          if (ceilf(fcycle) == fcycle) {
            cycles = (unsigned int)floorf(fcycle);
          } else {
            cycles = (unsigned int)floorf(fcycle) + 1;
          }
        }
        int index = find_minimum_stop(check_arr, questions[p] - diff * cycles,
                                      0, check_arr.size() - 1);
        unsigned int m_index = (unsigned int)index_saver[check_arr[index]];
        long long int result;
        result =
            (long long int)m_index + (long long int)n * (long long int)cycles;
        out_arr.push_back((long long int)result);
      }
    }
    ostringstream vts;
    copy(out_arr.begin(), out_arr.end() - 1, ostream_iterator<int>(vts, " "));
    vts << out_arr.back();
    final_output[i] = vts.str();
  }
  for (int m = 0; m < in_amount; m++) {
    cout << final_output[m] << endl;
  }
  return 0;
}
