#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;
/*
int dfs(int w,int h,int noww,int nowh,int n,int b){
	++n;
	if(noww>w || nowh>h) return 0;
	if(noww==w && nowh==h) return 1;
	int ret=0;
	for(int i=0; i<2; ++i){
		if(n>=2){
			n=0;
			if(i==0){
				b=1;
				ret+=dfs(w,h,++noww,nowh,n,b);
			} else if(i==1){
				b=2;
				ret+=dfs(w,h,noww,++nowh,n,b);
			}
		} else{
			if(b==1)ret+=dfs(w,h,++noww,nowh,n,b);
			if(b==2)ret+=dfs(w,h,noww,++nowh,n,b);
		}
	}
	return ret;
}

int main()u{
	int w,h;
	cin >> w >> h;
	cout << dfs(w,h,1,1,2,0) << endl;
	return 0;
}
*/
int calc(vector<int> balls,int i,int cas1,int cas2,int a,int sum);

int main(){
	int n;
	cin >> n;
	for(int i=0; i<n; ++i){
		vector<int> balls(10);
		for(int i=0 ;i<10; ++i){
			cin >> balls[i];
		}
		int sum=0;
		if(calc(balls,0,0,0,0,sum)>0){
			cout << "YES" << endl;
		} else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

int calc(vector<int> balls,int i,int cas1,int cas2,int a,int sum){
	if(i==10) {
		//cout << cas1 << " " << cas2 << " " << a << " " << balls[i-1] << endl;
		return 1;
	}
	if(a==0&&balls[i]<cas1) return 0;
	if(a==1&&balls[i]<cas2) return 0;
	if(a==0)cas1=balls[i];
	if(a==1)cas2=balls[i];
	sum += calc(balls,i+1,cas1,cas2,0,sum);
	sum += calc(balls,i+1,cas1,cas2,1,sum);

	return sum;
}