from math import ceil, sqrt n = int(input()) for i in range(n): a, b = map(int, input().split()) print( ceil(sqrt(a) + sqrt(b)) if sqrt(a) + sqrt(b) != int(sqrt(a) + sqrt(b)) else int(sqrt(a) + sqrt(b)) + 1 )