#include<iostream>
#include<queue>
using namespace std;

int main(void){
	queue<int> que;
	int b,c,n;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			cin >> b;
			que.push(b);
		}
		b = c = 0;
		bool flag = false;
		while(!que.empty()){
			if(que.front() > b){
				b = que.front();
				que.pop();
			}else if(que.front() > c){
				c = que.front();
				que.pop();
			}else{
				flag = true;
				break;
			}
		}
		if(flag){
			cout << "NO" << endl;
		}else{
			cout << "YES" << endl;
		}
	}
}