#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

class Pipe
{
private:
	queue<int> pipe;
	vector<int> a, b;
public:
	Pipe( queue<int> input )
	{
		pipe = input;
	}

	void pushA()
	{
		a.push_back( pipe.front() );
		pipe.pop();
	}

	void pushB()
	{
		b.push_back( pipe.front() );
		pipe.pop();
	}

	bool empty()
	{
		return pipe.size() == 0;
	}

	bool sorted()
	{
		for ( unsigned int i = 0; i + 1 < a.size(); i++ )
		{
			if ( a[i + 1] < a[i] )
			{
				return false;
			}
		}

		for ( unsigned int i = 0; i + 1 < b.size(); i++ )
		{
			if ( b[i + 1] < b[i] )
			{
				return false;
			}
		}

		return true;
	}
};

bool dfs()
{
	int buffer;
	queue<int> que;
	for ( int i = 0; i < 10; i++ )
	{
		cin >> buffer;
		que.push( buffer );
	}

	Pipe init( que );
	stack<Pipe> st;
	st.push( init );

	while ( !st.empty() )
	{
		Pipe current = st.top();
		st.pop();

		if ( current.empty() )
		{
			if ( current.sorted() )
			{
				return true;
			}
			else
			{
				continue;
			}
		}
		
		Pipe next = current;
		next.pushA();
		st.push( next );

		next = current;
		next.pushB();
		st.push( next );
	}

	return false;
}

int main()
{
	int n;

	cin >> n;

	for ( int i = 0; i < n; i++ )
	{
		cout << ( dfs() ? "YES" : "NO" ) << endl;
	}
	
	return 0;
}