object Main {
    def main(args:Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        for(i <- 1 to n) {
            val list = List.fill(10)(sc.nextInt)
            println(solve(list))
        }
    }
    def solve(list: List[Int]): String = {
        var c = 0
        for(i <- 1 to 9) {
            if(list(i) - list(i - 1) < 0) c += 1
        }
        if(c <= 2) "YES"
        else "NO"
    }
}