var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    input += chunk;
});
process.stdin.on('end', function() {
    main(input)
});

function main(input){
    var args = input.trim().split('\n');
    var dataSetCount = parseInt(args[0]);
    args = args.slice(1, dataSetCount + 1);
    args.forEach(function(set){
        set = set.split(' ').map(Number);
        console.log( solve(set) );
    })
}

function solve(set){
    var right = 0;
    var left = 0;
    for(var i = 0; i < set.length; i+=1){
        var ball = set[i];
        if(ball > right){ right = ball; }
        else if(ball > left){ left = ball; }
        else return "NO";
    }
    return "YES";
}