from sys import stdin input=lambda :stdin.readline()[:-1] def check(a,b,x): y=x*x-a-b if y>0 and y*y>4*a*b: return True return False def solve(): a,b=map(int,input().split()) ng,ok=-1,3*10**9 while abs(ng-ok)>1: mid=(ng+ok)//2 if check(a,b,mid): ok=mid else: ng=mid print(ok) for _ in range(int(input())): solve()