object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt)).toList.tail
    in.foreach(x => {
        val y = x diff x.head +: x.tail.foldLeft((x.head, Array[Int]())){
            case ((h, acc), n) => if(h < n) (n, acc :+ n) else (n, acc)
        }._2
        println(if (y sameElements y.sorted) "YES" else "NO")
    })
}