output_description: For each query, print the maximum possible number of participants whose scores
  are smaller than Takahashi's.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      Q
      A_1 B_1
      :
      A_Q B_Q
attempt: def examC():
      ABC = LI()
      ABC.sort()
      judge = ABC[2] * 2 - ABC[1] - ABC[0]
      ans = judge // 2 + (judge % 2) * 2
      print(ans)
      return
  
  
  def examD():
      def judge(A, B):
          cur = int((A * B) ** 0.5)
          if cur**2 == A * B:
              return (cur - 1) * 2 - 1
          if cur * (cur + 1) >= A * B:
              return cur * 2 - 2
          else:
              return cur * 2 - 1
  
      Q = I()
      ans = []
      for _ in range(Q):
          a, b = LI()
          ans.append(judge(a, b))
      for v in ans:
          print(v)
      return
  
  
  import sys, copy, bisect, itertools, heapq, math
  from heapq import heappop, heappush, heapify
  from collections import Counter, defaultdict, deque
  
  
  def I():
      return int(sys.stdin.readline())
  
  
  def LI():
      return list(map(int, sys.stdin.readline().split()))
  
  
  def LSI():
      return list(map(str, sys.stdin.readline().split()))
  
  
  def LS():
      return sys.stdin.readline().split()
  
  
  def SI():
      return sys.stdin.readline().strip()
  
  
  global mod, inf
  mod = 10**9 + 7
  inf = 10**18
  
  if __name__ == "__main__":
      examD()
  
problem_description: Statement
  
  10^{10^{10}} participants, including Takahashi, competed in two programming
  contests. In each contest, all participants had distinct ranks from first
  through 10^{10^{10}}-th.
  
  The _score_ of a participant is the product of his/her ranks in the two
  contests.
  
  Process the following Q queries:
  
    * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
samples: [{"input": "8\n    1 4\n    10 5\n    3 3\n    4 11\n    8 9\n    22 40\n    8 36\n    314159265 358979323", "output": "1\n    12\n    4\n    11\n    14\n    57\n    31\n    671644785\n    \n\nLet us denote a participant who was ranked x-th in the first contest and y-th\nin the second contest as (x,y).\n\nIn the first query, (2,1) is a possible candidate of a participant whose score\nis smaller than Takahashi's. There are never two or more participants whose\nscores are smaller than Takahashi's, so we should print 1."}]