#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int main()
{
	//freopen("3.txt","r",stdin);
	int n;
	cin >> n;
	int a[11];
	int b[2];
	int flag;
	b[0]=0;
	b[1]=0;
	while(n--)
	{
		flag=1;
		for(int i=0;i<10;i++)
			{
				cin >> a[i];
				sort(b,b+2);
				if(a[i]>b[1])
				{
					b[1]=a[i];
				}
				else if(a[i]<b[1]&&a[i]>b[0])
				{
					b[0]=a[i];
				}
				else if(a[i]<b[0])
					{
						flag=0;
					}
			}
		if(flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
 }
 return 0;
}