#include <iostream>
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a[20], b[20], c[20];
		for(int j = 0; j < 10; j++){
			cin >> a[j]; 
		}

		int ai = 0, bi = 0, ci = 0;
		b[0] = 0;
		c[0] = 0;
		while(ai < 10){
			if(b[bi] > c[ci]){
				if(a[ai] > b[bi]){
					bi++;
					b[bi] = a[ai];
					ai++;
				}else if(a[ai] > c[ci]){
					ci++;
					c[ci] = a[ai];
					ai++;
				}else{
					break;
				}
			}else{
				if(a[ai] > c[ci]){
					ci++;
					c[ci] = a[ai];
					ai++;
				}else if(a[ai] > b[bi]){
					bi++;
					b[bi] = a[ai];
					ai++;
				}else{
					break;
				}
			}
		}

		if(ai == 10){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}