#include<cstdio>
#include<iostream>
#include<stack>
using namespace std;


int main(){
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		int ball[10];
		for(int j=0;j<10;j++)scanf("%d",&ball[j]);
		
		stack<int> S,Q;
		int a[2]={0};
		a[0] = ball[0];
		S.push(a[0]);
		Q.push(a[1]);
		
		int k=1;
		bool OK = false;
		while(1){
			a[0] = S.top();
			a[1] = Q.top();
			if(a[0] < ball[k]){
				S.push(ball[k]);
				k++;
				if(k >= 10){
					OK = true;
					break;
				}
			}else if(a[1] < ball[k]){
				Q.push(ball[k]);
				k++;
				if(k >= 10){
					OK = true;
					break;
				}
			}else{
				S.pop();
				Q.pop();
				k--;
			}
			if(S.size() == 0) break;
		}		
		if(OK == true) printf("YES\n");
		else printf("NO\n");
		
	}
	return 0;
}