import scala.collection.mutable import scala.io.StdIn.* import scala.math.* @main def main = val testCase = readLine().toInt for _ <- 0 until testCase do val n = readLine().toInt val permutation = readLine().split(' ').map(_.toInt) val isUpper = Array.fill(n){true} var count = 1 var result = 0 for i <- permutation.indices.sortBy(permutation) do if i > 0 then if isUpper(i - 1) == isUpper(i) then count += 1 else count -= 1 if i + 1 < n then if isUpper(i) == isUpper(i + 1) then count += 1 else count -= 1 isUpper(i) = false result = max(result, count) println(result)