object Main {
  def main(args : Array[String]): Unit ={
    val scanner = new java.util.Scanner(System.in)
    val i = scanner.nextInt()
    val lines = List.fill(i)(List.fill(10)(scanner.nextInt()))
    val result = lines.map(check(_ , 0 , 0)).map{if (_) "YES" else "NO"}
    result.foreach(println)

  }

  def check (rest : List[Int], l : Int , r : Int) : Boolean ={
    rest match {
      case Nil => true
      case x :: xs =>
        (x >  l && check(xs ,x , r)) || (x > r && check(xs, l, x))
    }
  }
}