fun main(args: Array<String>) {
    var Q = nextInt()
    repeat(Q) {
        val (A, B) = listOfLong()
        val ans = when {
            (A == B) -> 2 * A - 2
            (A + 1 == B || B + 1 == A) -> 2 * Math.min(A, B) - 2
            else -> {
                val ab = A * B
                var d = Math.sqrt(ab.toDouble()).toLong()
                if (d * d == ab) d--
                if (d * (d + 1) >= ab) 2 * d - 2 else 2 * d - 1
            }
        }
        println(ans)
    }
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfLong(d: Long = 0) = listOfString().map { it.toLong() + d }
