#include <iostream>
#include <stack>
#include <algorithm>

using namespace std;

struct Channel{
	int channels[2];
	Channel(){
		channels[0] = -1;
		channels[1] = -1;
	}
	bool update(int index, int number){
		if(number > channels[index]){
			channels[index] = number;
			return true;
		}
		else
			return false;
	}
};

int number[10];
int n;

bool dfs(Channel c, int depth){
	if(depth == 10)
			return true;
	Channel c_tmp = c;
	return (c.update(0, number[depth]) && dfs(c, depth+1))
			|| (c_tmp.update(1, number[depth]) && dfs(c_tmp, depth+1));

}

void solve(){
	if(dfs(Channel(), 0))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

int main(){
	cin >> n;
	while(n--){		
		for(int i=0; i<10; ++i){
			cin >> number[i];
		}
		solve();
	}
	return 0;
}
