fun main(arr:Array<String>) {
    val q = readLine()!!.toInt()
    val ans = (1..q).map { readLine()!!.split(" ").map { it.toLong() }.sorted().let { getAns(it[0], it[1]) }}
    ans.forEach { println(it) }
}

fun getAns(a:Long, b:Long):Long {
    if(b-a <= 1) {
        return (a-1)+(a-1)
    }
    val c = sqrt(a*b-1, 1, Math.min(a*b-1, 1e9.toLong()))
    if(c*(c+1) >= a*b) {
        return 2*c-2
    }
    return 2*c-1
}

fun sqrt(num:Long, min:Long, max:Long):Long {
    if(max - min <= 1) {
        if(max*max <= num) {
            return max
        } else {
            return min
        }
    }
    val mid = (max+min)/2
    val tmp = mid*mid
    if(tmp > num) {
        return sqrt(num, min, mid)
    } else if(tmp < num) {
        return sqrt(num, mid, max)
    }
    return mid
}
