import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    for (i in 1..N) {
        val a = Array(10) { sc.nextInt() }
        val container = arrayOf(0, 0)
        var flag = true
        for (n in a) {
            if (container[0] < n) container[0] = n
            else if (container[1] < n) container[1] = n
            else { flag = false; println("NO"); break }
            container.sortDescending()
        }
        if (flag) println("YES")
    }
}
