import scala.io.Source.stdin
import scala.io.StdIn
import scala.util.control.Breaks

/**
  * Created by wintermaples on 2017/06/20.
  */
object Main {

  def main(args : Array[String]) : Unit = {
    val b = new Breaks
    val n = StdIn.readLine().toInt
    for (i <- 0 until n) {
      val balls = StdIn.readLine().split(" ").map(_.toInt).reverse
      var ballLine1 = List.empty[Int]
      var ballLine2 = List.empty[Int]
      var success = true
      for (j <- 0 until balls.length) {
        b.breakable {

          if (ballLine1.isEmpty) {
            ballLine1 :+= balls(j)
            b.break()
          }
          if (ballLine2.isEmpty) {
            ballLine2 :+= balls(j)
            b.break()
          }
          if (ballLine1(ballLine1.length - 1) > balls(j)) {
            ballLine1 :+= balls(j)
            b.break()
          }
          if(ballLine2(ballLine2.length - 1) > balls(j)) {
            ballLine2 :+= balls(j)
            b.break()
          }
          success = false

        }
      }
      if (success)
        println("YES")
      else
        println("NO")

    }
  }

}