#include<cstdio>
#include<algorithm>
#define MAXL 10
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int t,last1=0,last2=0;	//假?last1>last2
		bool flag=0;
		for(int j=1;j<=10;j++){
			scanf("%d",&t);
			if(last1<t)	last1=t;
			else
				if(last2<t)	last2=t;
				else flag=1;
			if(last1<last2)	swap(last1,last2);
		}
		if(flag==0)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}