import math from decimal import Decimal, getcontext, ROUND_CEILING getcontext().prec = 20 n = int(input()) for _ in range(n): a, b = map(int, input().split()) # Check if a is a perfect square a_root = math.isqrt(a) is_a_square = a_root * a_root == a # Check if b is a perfect square b_root = math.isqrt(b) is_b_square = b_root * b_root == b if is_a_square and is_b_square: print(a_root + b_root + 1) else: sum_sqrt = Decimal(a).sqrt() + Decimal(b).sqrt() x = sum_sqrt.to_integral_value(rounding=ROUND_CEILING) print(int(x))