#include<stdio.h>
	int data[10];

int push(int right,int left,int i)
{
	if(i>=9)
		return 1;

	if(data[i]<right && data[i]<left)
		return 0;
	else
	{
		if(data[i]>right)
			if(push(data[i],left,i+1))
				return 1;
		if(data[i]>left)
			if(push(right,data[i],i+1))
				return 1;
	}
	return 0;
}

int main()
{
	int loop;
	scanf("%d",&loop);
	for(int j=0;j<loop;j++)
	{
		int right=0;int left=0;
		for(int i=0;i<10;i++)
			scanf("%d",&data[i]);

		if(push(right,left,0))
			printf("YES\n");
		else 
			printf("NO\n");
	}
}