def wa(pos): return pos*(pos+1)//2 T=int(input()) for i in range(T): N,X=map(int,input().split()) ans=[] if wa(N)>X: print(-1) continue for i in range(N-1): ok=X-wa(N-i-1) ng=0 while ok-ng>1: mid=(ok+ng)//2 now=X-mid-wa(N-i-1) if now<0: ng=mid continue if (N-i-1)+(now+N-i-2)//(N-i-1)