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 count = 0;
    for(var i=0; i<set.length; i+=1){
        if(set[i] < set[i-1]){
            count+=1;
        }
    }
    var isOver = count > 2;
    return isOver ? "NO" : "YES";
}