object Main extends App {
	val q = scala.io.StdIn.readInt
	val ans = new Array[Long](q)

	for(i<-0 until q){
		val Array(a, b) = scala.io.StdIn.readLine.split(" ").map(_.toLong)

		val x = math.min(a,b)
		val y = math.max(a,b)

		if(x == y){
			ans(i) = 2L*x - 2L
		}else if(x+1L == y){
			ans(i) = 2L*x - 2L
		}else{
			lazy val z = {
				val tp = math.sqrt(a*b).toLong
				if(tp*tp == a*b){
					tp - 1L
				}else{
					tp
				}
			}

			if(z*(z+1L) >= x*y){
				ans(i) = 2L*z - 2L
			}else{
				ans(i) = 2*z - 1L
			}
		}

		
	}

	for(x<-ans){
		println(x)
	}
}