import scala.io.StdIn.{readInt, readLine}
import scala.annotation.tailrec

object Main extends App {

  val n     = readInt()
  val lines = Iterator.fill(n)(readLine())

  val result = for {
    line <- lines
    balls = line.split(" ").map { _.toInt }
  } yield if (solve(balls)) "YES" else "NO"

  result.foreach(println)

  def solve(balls: Seq[Int]): Boolean = {

    @tailrec
    def go(xs: List[Int], accum: (List[Int], List[Int])): Boolean = {
      xs match {
        case Nil     => true
        case y :: ys =>
          val nextLists = accum match {
            case (Nil, Nil) => Some((List(y), Nil))

            case (Nil, right @ rh :: _)            =>
              if (y > rh) Some((Nil, y :: right))
              else Some((List(y), right))

            case (left @ lh :: _, Nil)             =>
              if (y > lh) Some((y :: left, Nil))
              else Some((left, List(y)))

            case (left @ lh :: _, right @ rh :: _) =>
              if (lh > rh) {
                if (y > lh) Some((y :: left, right))
                else if (y > rh) Some((left, y :: right))
                else None
              } else {
                if (y > rh) Some((left, y :: right))
                else if (y > lh) Some((y :: left, right))
                else None
              }
          }

          nextLists match {
            case Some(z) => go(ys, z)
            case None    => false
          }
      }
    }

    go(balls.toList, (Nil, Nil))
  }

}

