fun main(args: Array<String>) {
    val Q = readLine()!!.toInt()

    fun sqrt(t: Long): Long {
        var l = 1L
        var u = 2e9.toLong()

        while (u - l > 1) {
            val c = (l + u) / 2

            if (c * c > t) {
                u = c
            } else {
                l = c
            }
        }

        return l
    }

    for (q in 1..Q) {
        val (A, B) = readLine()!!.split(" ").map{it.toLong()}

        if (Math.max(A, B) == 1L) {
            println(0)
            continue
        }

        val M = A * B - 1
        val L = sqrt(M)
        var T = L * 2

        if (L == M / L) {
            T -= 1L
        }
        if (Math.min(A, B) <= L) {
            T -= 1L
        }

        println(T)
    }
}
