var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
Arr.shift();
Arr.forEach(function(V){
var arr=V.split(" ").map(Number);
var a=0;
var b=0;
var flag=true;
for(var i=0;i<arr.length;i++){
var v=arr[i];
if(a<v){a=v;continue;}
if(b<v){b=v;continue;}
flag=false;
}
console.log(flag?"YES":"NO");
});