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

    while (u - l > 1L) {
        val c = (l + u) / 2
        if (c * c <= n) {
            l = c
        } else {
            u = c
        }
    }

    return l
}

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

    for (i in 1..Q) {
        val (a, b) = readLine()!!.split(" ").map{it.toLong()}
        val A = Math.min(a, b)
        val B = Math.max(a, b)

        if (B == 1L) {
            println(0)
            continue
        }

        val M = A * B - 1
        val L = sqrt(M)
        var t = 2 * L - if (M / L == L) { 1 } else { 0 }
        if (A <= L) {
            t--
        }

        println(t)
    }
}