#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>

using namespace std;

int ball[16];

bool dfs(int i, int prevB, int prevC)
{
	if(i == 10)
	{
		return true;
	}
	if(ball[i] > prevB)
	{
		return dfs(i+1, ball[i], prevC);
	}
	if(ball[i] > prevC)
	{
		return dfs(i+1, prevB, ball[i]);
	}
	return false;
	
}

int main()
{
	int n;

	cin >> n;

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < 10; j++)
		{
			cin >> ball[j];
		}

		if(dfs(0, 0, 0))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}