import sys def input(): return sys.stdin.readline().rstrip() def main(): N = int(input()) for i in range(N): a, b = map(int, input().split()) X = 0 ab4 = a*b*4 for j in range(9, -1, -1): x = X+2**j if x**2 - a - b <= 0: X = x continue if (x**2-a-b)**2 <= ab4: X = x print(X+1) if __name__ == "__main__": main()