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

int[] value;

string dfs(int left,int right,int i)
{
	if(i == 10) return "YES";
	if(left < value[i])
	{
		return dfs(value[i],right,i+1);
	}
	if(right < value[i])
	{
		return dfs(left,value[i],i+1);
	}
	return "NO";
}


int main()
{
	value.length = 10;
	int n = readln.chomp.to!int;
	foreach(i;0..n)
	{
		string[] s = readln.chomp.split(" ");
		foreach(j;0..10)
		{
			value[j] = s[j].to!int;
		}
		writeln(dfs(0,0,0));
	}
	return 0;
}