import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	auto n = readln.chomp.to!int;

	foreach (i; 0..n) {
		auto as = readln.split.map!(to!int);
		auto left = int.min;
		auto right = int.min;
		foreach (a; as) {
			if (left < a) left = a;
			else if (right < a) right = a;
			else {
				writeln("NO");
				return;
			}
		}
		writeln("YES");
	}
}