import std.stdio, std.conv, std.algorithm, std.array, std.string;

void main(){
	int n = to!int(readln.chomp);
	foreach(_; 0..n){
		auto ns = array(map!(to!int)(readln.chomp.split));
		writeln(solve(ns) ? "YES" : "NO");
	}
}

bool solve(int[] ns){
	foreach(bit; 0..1<<ns.length){
		int[2] prev;
		bool ok = true;
		foreach(i; 0..ns.length){
			if(prev[(bit>>i)&1] < ns[i]){
				prev[(bit>>i)&1] = ns[i];
			}
			else{
				ok = false;
				break;
			}
		}
		if(ok){
			return true;
		}
	}
	return false;
}