import scala.io.StdIn._

object Main {
  def checkLeftRight(l: List[Int],
    rl: Vector[Int] = Vector(0), ll: Vector[Int] = Vector(0)): Boolean = {
    if (l.isEmpty) true
    else {
      if (l.head > rl.last) checkLeftRight(l.tail, rl :+ l.head, ll)
      else if (l.head > ll.last) checkLeftRight(l.tail, rl, ll :+ l.head)
      else false
    }
  }

  def setBall(s: String): String = {
    val ballList = s.split(" ").map(_.toInt).toList
    val canSetBall = checkLeftRight(ballList)
    if (canSetBall) "YES" else "NO"
  }

  def results(n: Int, result: Vector[String] = Vector()): Vector[String] = n match {
    case 0 => result
    case _ => results(n - 1, result :+ setBall(readLine()))
  }

  def main(args: Array[String]): Unit = {
    results(readInt()).foreach(println)
  }
}