#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        int s;
        cin >> s;
        vector<int> a(n+5), p(n+5);
        for(int i = 1; i <= n; i++){
            cin >> a[i];
            p[i] = p[i-1] + a[i];
        }
        if(p[n] < s){
            cout << "-1\n";
            continue;
        }

        int l = 0, r = n, ans = n;
        while(l <= r){
            int mid = (l + r) / 2;
            bool ok = false; 
            for(int i = 0; i <= mid; i++){
                if(p[n-(mid-i)] - p[i] <= s){
                    ok = true;
                    break;
                }
            }
            if(ok){
                ans = mid;
                r = mid - 1;
            }else{
                l = mid + 1;
            }
        }
        cout << ans << "\n";
    }
}


