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 a = 0
        var b = 0
        var f = true
        for(i <- 0 to 9) {
            if(list(i) < a && list(i) < b) {
                f = false
            }
            else if(a < list(i) && list(i) < b) a = list(i)
            else if(list(i) < a && b < list(i)) b = list(i)
            else if (a < b) b = list(i)
            else a = list(i)
        }
        if(f) "YES"
        else "NO"
    }
}