#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <iostream>
#define FOR(i,l,r) for (int i=(l);i<=(r);i++)
using namespace std;
const int maxn=500000+1;
typedef long long LL;

int n,x;
LL sum[maxn];
int sta[maxn]; int pos;
int ef(LL d)
{
    int l=1,r=pos,mid;
    while (l<=r)
    {
        mid=l+r>>1;
        if (sum[sta[mid]]<=d) l=mid+1;
        else r=mid-1;
    }
    return r;
}
int main(){
    for (int T;scanf("%d",&T)!=EOF;)
        for (int p,ans;T--;)
        {
            scanf("%d%d",&n,&x);
            FOR (i,1,n) scanf("%d",&p),sum[i]=sum[i-1]+p;
            ans=n+1; sta[pos=1]=0;
            FOR (i,1,n)
            {
                p=ef(sum[i]-x);
                if (p) ans=min(ans,i-sta[p]);
                while (pos&&sum[sta[pos]]>=sum[i]) pos--;
                sta[++pos]=i;
            }
            printf("%d\n",ans==n+1?-1:ans);
        }
    return 0;
}