#include<stdio.h>
bool tansaku(int count,int n1,int n2,int ans[],int a[],int b[],bool flg)
{
	if (count == 10)
	{
		return true;
	}
	if (flg == false)
	{
		if (a[n1] < ans[count])
		{
			n1++;					
			a[n1] = ans[count];
			count++;
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			if (hozon == true)
			{
				flg = true;
			}
		}
		if (b[n2] < ans[count])
		{
			n2++;
			b[n2] = ans[count];
			count++;
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			if (hozon == true)
			{
				flg = true;
			}
		}
	}
	return flg;
}
int main(void)
{
	int n = 0;
	int a[10] = {0};
	int damy[20] = {0};
	bool ans_flg[1000] = {false};
	scanf("%d",&n);
	for (int i = 0;i < n;i++)
	{
		scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
		if (tansaku(0,0,0,a,damy,damy,false) == true)
		{
			ans_flg[i] = true;
		}
	}
	for (int i = 0;i < n;i++)
	{
		if (ans_flg[i] == true)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}