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);
		int l ,r;
		bool f;
		foreach (a; as) {
			if (l < a) l = a;
			else if (r < a) r = a;
			else {
				f = true;
			}
		}
		writeln(f?"NO":"YES");
	}
}