#include #define ll long long using namespace std; int T,n; ll m,a[100005],sum,maxsum,L,H[100005],nw,MM[100005],Mn; int fa[100005],A,fl; ll read(){ ll x=0,v=0;char ch=getchar(); while(!isdigit(ch)) v|=(ch=='-'),ch=getchar(); while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); return v?-x:x; } void print(ll x){ if(x>=10) print(x/10); putchar(x%10+'0'); } int find(int x){ if(x==fa[x]) return x; return fa[x]=find(fa[x]); } int main(){ T=read(); while(T--){ n=read(),m=read(); for(int i=1;i<=n;i++) a[i]=read(),fa[i]=i,H[i]=a[i]; sum=maxsum=0,Mn=MM[0]=0; fl=0; for(int i=1;i<=n;i++){ if(sum+a[i]<0) sum=0,fl=1; else{ sum+=a[i]; if(i>1&&!fl) fa[i-1]=i,H[i]+=H[i-1]; fl=0; } maxsum=max(maxsum,sum); Mn+=a[i],MM[i]=max(MM[i-1],Mn); } maxsum=max(maxsum,sum); L=0,fl=0,nw=0; while(L<=3*n){ L++; A=find(1); while(A=0){ fa[A]=fa[find(A+1)],H[find(A+1)]+=H[A]; A=find(A+1); } else break; } if(nw+MM[find(1)]>=m||maxsum>=m){ nw=max(nw+MM[find(1)],maxsum); fl=1;break; } if(find(1)==find(n)){ L--; break; } nw=max(0ll,H[find(n)]); } if(find(1)!=find(n)&&!fl) puts("-1"); else{ if(nw>=m) print(L); else if(nw+MM[n]>=m) print(L+1); else{ if(H[find(1)]!=0) print(L+(m-MM[n]-nw-1)/H[find(1)]+2); else printf("-1"); } puts(""); } } return 0; }