#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int N;
int A_bottle[10];

stack<int> B_bottle,C_bottle;

bool dfs(int i){
	//A????????????i???????????°?????????????????????
	if (i==10){
		//?????????????????????????????????????????????
		return true;
	}
	bool flg=false;

	if (B_bottle.empty() || B_bottle.top()<A_bottle[i]){
		//B????????????????????????
		B_bottle.push(A_bottle[i]);
		flg=dfs(i+1);
		B_bottle.pop();
		if (flg) return true;
	}
	if (C_bottle.empty() || C_bottle.top()<A_bottle[i]){
		//C????????????????????????
		C_bottle.push(A_bottle[i]);
		flg=dfs(i+1);
		C_bottle.pop();
		if (flg) return true;
	}
	return false;
}

int main(){
	vector<bool> out;
	cin>>N;
	for (int i=0;i<N;i++){
		for (int j=0;j<10;j++){
			cin>>A_bottle[j];
		}
		out.push_back(dfs(0));
	}
	for (vector<bool>::iterator ite=out.begin();ite!=out.end();ite++){
		cout<<(*ite ? "YES" : "NO")<<endl;
	}
	return 0;
}