object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    in.next
    in.foreach(r => {
        var s = (11, 11)
        if (r.foldLeft(true)((f, d) => {
            f && (if (s._1 > d) {s = (d, s._2); true}
            else if (s._2 > d) {s = (s._1, d); true}
            else false
        )})) println("YES") else println("NO")
    })
}