import math from sys import stdin n = int(input()) for _ in range(n): a, b = list(map(int, stdin.readline().split())) temp = a**0.5 + b**0.5 tempAns = math.ceil(temp) for i in range(-1, 2): if tempAns+i > temp: tempAns = tempAns+i break print(tempAns)