#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool check(const vector<int> & ary,int i,int l,int r)
{
	if(i == 10)
		return true;
	bool f = false;
	if(ary[i] > l)
	{
		f = check(ary,i+1,ary[i],r);
	}
	if(ary[i] > r)
	{
		f = f || check(ary,i+1,l,ary[i]);
	}
	return f;
}

int main (int argc, char const* argv[])
{
	int n;
	cin >> n;
	for (unsigned int i = 0; i < n; i += 1)
	{
		auto ary = vector<int>(10);
		for (unsigned int i = 0; i < 10; i += 1)
		{
			cin >> ary[i];
		}
		bool f = check(ary,0,0,0);
		if(f)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	return 0;
}