#include<iostream>
using namespace std;
int main(){
	int row[2],order[10],memo[10][2],n;
	cin >>n;
	for(int i=0; i<n; i++){
		for(int l=0; l<10; l++){
			cin >>order[l];
		}
		row[0] = order[0];
		row[1] = 0;
		int x = 0,l;
		for(l=1; l<10; l++){
			if(row[0]<order[l] && row[1]>order[l]){row[0] = order[l];}
			else if(row[0]>order[l] && row[1]<order[l]){row[1] = order[l];}
			else if(row[0]<order[l] && row[1]<order[l]){
				memo[x][0] = row[0];
				memo[x][1] = l;
				row[0] = order[l];
				x++;
			}
			else if(row[0]>order[l] && row[1]>order[l]){
				if(x == 0){cout <<"NO"<<endl;break;}
				else{
					x--;
					row[0] = memo[x][2];
					l = memo[x][1];
					row[1] = order[l];
				}
			}
		}
		if(l == 10){cout <<"YES"<<endl;}
	}
	return 0;
}