

object Main extends App {
  import scala.io.StdIn._
  val n = readLine.trim.toInt
  for (_ ← 0 until n){
    val nums = readLine.trim.split(' ').map(_.toInt).toList
    println(
      if (canMake(nums)) "YES"
      else "NO"
    )
  }
  def canMake(num: List[Int], left: Int = 0, right: Int = 0): Boolean = {
    num match{
      case Nil ⇒ true
      case h::t if h > left && h > right ⇒ canMake(t, h, right) || canMake(t, left, h)
      case h::t if h > left ⇒ canMake(t, h, right)
      case h::t if h > right ⇒ canMake(t, left, h)
      case _ ⇒ false
    }
  }
}
