#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long INF = 1e18;
long long a[N], s[N], t, n, m, x;
int main() {
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld%lld", &n, &m);
    bool flag = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
      s[i] = s[i - 1] + a[i];
      if (s[i] > 0) flag = 1;
    }
    for (int i = 1; i <= m; i++) {
      long long ans = INF;
      scanf("%lld", &x);
      if (!flag && s[n] <= 0) {
        printf("-1 ");
        continue;
      }
      for (int j = 1; j <= n; j++)
        if (s[n]) {
          if (((x - s[j]) / s[n]) * s[n] == x - s[j] && (x - s[j]) / s[n] >= 0)
            ans = min(ans, (x - s[j]) / s[n] * n + j - 1);
        } else if (x == s[j])
          ans = min(ans, 1ll * j - 1);
      printf("%lld ", (ans == INF) ? -1 : ans);
    }
    printf("\n");
  }
  return 0;
}
