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

object Main {

  def insert(l:List[Int],b:Int,c:Int):Boolean =
    l match {
      case Nil => true
      case hd::tl =>
        if(b<hd) insert(tl,hd,c)
        else if(c<hd) insert(tl,b,hd)
        else false
    }

  def main(args:Array[String]) =
    println {
      {
        for(i<-0 until readInt) yield if(insert(readLine.split(" ").map(_.toInt).toList,0,0)) "YES" else "NO"
      }.mkString("\n")
    }
}