
object Main extends App{
  import scala.io.StdIn._
  import scala.math._
  val q = readLine().trim().toInt
  for (_ <- 0 until q){
    val (a::b::_) = readLine().trim().split(' ').map(_.toLong).toList
    val sqrt = math.sqrt(a * b).toLong
    println(if (sqrt * (sqrt + 1) < a * b){//
      sqrt * 2 - 1      
    }else if (sqrt * sqrt != a * b) {
      sqrt * 2 - 2
    }else{
      if (a == b) sqrt * 2 - 2
      else sqrt * 2 - 3
    })
  }
}