// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();

function main(){
  for(var i = 0, len = input[0] - 0; i < len; i++){
    var c = input[i+1].split(' ');
    var a = b = 0;

    for(var j = 0, jlen = c.length; j < jlen; j++){
      if((d = +c[j]) > a)
        a = d;
      else if(d > b)
        b = d;
      else
        a = b = 11;
    }

    console.log(a==11?'NO':'YES');
    
  }

  
}