#include <bits/stdc++.h>
using namespace std;
long long a[200010];
long long sum[200010];
map<long long, int> mp;
void solve(int T) {
  int n, m;
  cin >> n >> m;
  mp.clear();
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
    if (mp[sum[i]])
      continue;
    else
      mp[sum[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    long long x;
    cin >> x;
    if (mp[x]) {
      cout << mp[x] - 1 << " ";
      continue;
    }
    if (sum[n] == 0 || x < sum[n] || (x > 0 && sum[n] < 0)) {
      cout << "-1 ";
      continue;
    }
    long long t = x / sum[n];
    x = x % sum[n];
    if (x == 0) {
      cout << t * n - 1 << " ";
      continue;
    }
    if (mp[x]) {
      cout << t * n + mp[x] - 1 << " ";
      continue;
    }
    cout << "-1 ";
  }
  cout << endl;
}
signed main() {
  int t = 1;
  scanf("%d", &t);
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
  return 0;
}
