#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cstring>
using namespace std;

using namespace std;
bool solve(deque<int> toAdd, deque<int> l,deque<int> r){
	if(toAdd.size()==0)return true;
	bool flag = false;
	if(l[l.size()-1]<toAdd.front()){
		int j = toAdd.front();
		toAdd.pop_front();
		l.push_back(j);
		flag = flag || solve(toAdd,l,r);
		//back to original problem
		toAdd.push_front(j);
	        l.pop_back();
	}
	if(flag)return true;
	if(r[r.size()-1]<toAdd.front()){
		int j = toAdd.front();
		toAdd.pop_front();
		r.push_back(j);
		flag = flag || solve(toAdd,l,r);
	}
	return flag;
}
int main(){
	int n;
	cin>>n;
	while(n-->0){
		deque<int> balls;
		for(int x=0;x<10;++x){
			int j;cin>>j;
			balls.push_back(j);
		}
		deque<int> sol;sol.push_back(0);
		if(solve(balls,sol,sol)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}