#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main(void)
{
	int n,i,j;
	stack<int>s1,s2;
	int table[10];
	cin >> n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<10;j++)
		{
			cin >> table[j];
		}
		s1.push(0);
		s2.push(0);
		for(j=0;j<10;j++)
		{
			if(s1.top()<table[j])
			{
				if(s2.top()<table[j])
				{
					if(s1.top()>s2.top())
					{
						s1.push(table[j]);
					}
					else
					{
						s2.push(table[j]);
					}
				}
				else
				{
					s1.push(table[j]);
				}
			}
			else
			{
				break;
			}
		}
		if(j==10)cout <<"YES"<< endl;
		else cout << "NO" << endl;
	}
	return 0;
}