from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = int(input()) for _ in range(N): a,b = map(int,input().split()) is_ok = lambda x : 4*a*b < (x**2 - a - b)**2 x = math.ceil(math.sqrt(a+b)) y = a+b+10 while y-x>1: mid = (y+x)//2 if is_ok(mid): y = mid else: x = mid print(y)