#include<iostream>
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int l=0; l < n; l++){
		bool isLined = true;
		int num[10];
		int b = -1, c = -1;
		for(int i=0; i < 10; i++){
			cin >> num[i];
		}

		for(int i=0; i < 10; i++){
			if(num[i] < b && num[i] < c){
				isLined = false;
				break;
			}
			else if(b < num[i] && c < num[i]){
				if(b < c) c = num[i];
				else b = num[i];
			}
			else if(b < num[i]){
				b = num[i];
			}
			else c = num[i];
		}
		if(isLined) cout << "YES" << endl;
		else cout << "NO" << endl;

	}
}