from decimal import * getcontext().prec = 20 N = int(input()) for i in range(N): a, b = map(int, input().split()) X = Decimal(a).sqrt()+Decimal(b).sqrt()+Decimal(1) X.to_integral_exact(rounding=ROUND_FLOOR) print(X)