      subroutine solve ( a, b, ans )
        integer*8 a, b, ans
        integer*8 lim, low, high
        integer*8 mid, mul
        if ( a .eq. b ) then
          ans = (a-1)*2
          return
        endif

        lim = a*b - 1
        low  = 1
        high = 1
        high = ishft(high, 32)
        do while( high - low > 1 )
          mid = (low + high) / 2
          mul = (mid+1)/2 * (mid+1 - (mid+1)/2)
          if ( mul .gt. lim ) then
            high = mid;
          else
            low = mid;
          endif
        enddo
        ans = low - 1
        RETURN
      end

      program main
        implicit none
        integer*8 I, Q
        integer*8 A, B, ans
        read(*,*) Q

        do I = 1, Q
          read(*,*) A, B
          call solve(A, B, ans)
          write(*,*) ans
        enddo
      end