#include<cstdio>
#define MAX(x,y) ((x>y)? x:y)

using namespace std;

int BOX[2];
int n;
int DATE[10];
bool answer=true;


int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		BOX[0]=0;BOX[1]=0;
		for(int j=0;j<10;j++)
		{
			scanf("%d",&DATE[j]);
		}
		for(int j=0;j<10;j++)
		{
			if(j==0)BOX[0]=DATE[j];
			else
			{
				if(BOX[0]>DATE[j]&&BOX[1]>DATE[j])answer=false;
				else if(BOX[0]>DATE[j])BOX[1]=DATE[j];
				else if(BOX[1]>DATE[j])BOX[0]=DATE[j];
				else if(BOX[0]>BOX[1])BOX[0]=DATE[j];
				else BOX[1]=DATE[j];

			}
		}
		if(answer==true) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}