import math # k 個食べられるかは、 # A = N - B として # binom(A,k) / binom(N,k)*k # binom(A,k) / (N binom(N-1,k-1)) # (N-k)! / (A-k)! / (k-1) # A! / N! # (N-x) * (A-x) / x * (x - 1) T = int(input()) def f(x): return math.factorial(x) def solve(): N, B = map(int, input().split()) A = N - B ok = 0 ng = A + 1 # (A-x)(x+1) / (N-x)x は単調減少。1以下になるのはどこ? while ng - ok > 1: x = (ok + ng) >> 1 if (A-x)*(x+1) >= (N-x)*x: ok = x else: ng = x print(ok + 1) for _ in range(T): solve()