ll@t; rep(t){ ll@n,@m,@l[n],@r[n]; ll a=-1,b=m+2; while(a+1>1; ll s=0; rep(i,n){ s+=min(max(c,l[i]),r[i]); } if(s<=m){ a=c; }else{ b=c; } } if(a<0||a>m){ wt(-1); }else{ ll s=m; rep(i,n){ s-=min(max(a,l[i]),r[i]); } ll y=0,z=0; rep(i,n){ ll x=min(max(a,l[i]),r[i]); if(s>0&&x