#include #define mp make_pair #define fi first #define se second #define debug(x) cerr << #x << " = " << (x) << endl #define EPS 1e-9 #define PI acos(-1.0) using namespace std; void test() { cerr << endl; } template void test(T x, Args... args) { cerr << x << " "; test(args...); } typedef long long ll; typedef pair pii; typedef pair pll; const int MAXN = (int)1e5 + 10; const int MOD = 998244353; const int INF = 1e9; ll a[MAXN], sum[MAXN]; void Main() { int n; ll m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; sum[i] = sum[i-1] + a[i]; } auto cal = [&](ll x) { if (x >= m) return 0; for (int i = 1; i <= n; i++){ x = max(0ll, x + a[i]); if (x >= m) return i; } return -1; }; ll l = 0, r = m, st = r; while (l <= r) { ll mid = (l + r) / 2; if (cal(mid) != -1) { st = mid; r = mid - 1; } else { l = mid + 1; } } ll ans = -1; if (st == 0) { ans = 1; } else { ll mi = *min_element(sum + 1, sum + 1 + n); if (mi < 0) { ll tmp = sum[n] - mi; if (tmp >= st) { ans = 1 + (cal(tmp) > 0); } else { if (tmp + mi > 0) { ll ti = (st - tmp + sum[n] - 1) / sum[n]; ans = 1 + ti + (cal(tmp + ti * sum[n]) > 0); } } } else { ll ti = (st + sum[n] - 1) / sum[n]; ans = ti + (cal(ti * sum[n]) > 0); } } cout << ans << "\n"; } int main() { #ifdef BanFcc freopen("in.txt", "r", stdin); /// freopen("out.txt", "w", stdout); #else ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); #endif int T = 1; cin >> T; for (int ca = 1; ca <= T; ca++) { // cout << "Case #" << ca << ": "; Main(); } return 0; }