import sys input = lambda: sys.stdin.readline().rstrip() def naive(A, B): ng = -1 ok = (A+B)*2 while abs(ng-ok) > 1: mid = (ok+ng)//2 if mid*mid-A-B > 0 and 4*A*B < (mid*mid-A-B)**2: # ここ頑張る ok = mid else: ng = mid return ok def isqrt(n): # n <= X^2 なる最小の X を求める ng = 0 ok = n*2 while abs(ng-ok) > 1: mid = (ok+ng)//2 if n <= mid*mid : # ここ頑張る ok = mid else: ng = mid return ok def solve(A, B): # vA + vB < X # A + 2vAB + B < X2 # 2vAB < X2 - A - B =: C # 4AB < C2 iseq = True C = isqrt(4*A*B) iseq &= 4*A*B == C * C X = isqrt(C+A+B) iseq &= C+A+B == X * X return X+iseq def main(): # 入力 N = int(input()) for _ in range(N): A, B = map(int, input().split()) # 計算・出力 ans = naive(A, B) print(ans) if __name__ == "__main__": main() from random import randint # for _ in range(10000): # A = randint(1, 10**9) # B = randint(1, 10**9) # ans1 = naive(A, B) # ans2 = solve(A, B) # if ans1 != ans2: # print(A, B) # print(ans1, ans2) # break