import math N=int(input()) for _ in range(N): A,B=map(int,input().split()) left,right=0,3*10**3 while right-left>1: mid=(right+left)//2 if 4*A*B<(mid**2-A-B)**2: right=mid else: left=mid print(int(right))