#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define range(m,n) for(int i = m; i < n; i++)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	vector<int> b(10);
	int n;
	int c1,c2;

	while(cin >> n){
		range(0,n){
			c1 = c2 = 11;
			range(0,10){
				cin >> b[i];
			}
			range(0,10){
				int back = b[9-i];
				if(back < c1){
					c1 = back;
					b.pop_back();
					continue;
				}else if(back < c2){
					c2 = back;
					b.pop_back();
				}else{
					break;
				}
			}
			if(b.empty()) cout << "YES" << endl;
			else cout << "NO" << endl;
			b.clear();
		}
	}
}