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

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		bool z = true;
		int a[10];
		for(int j=0;j<10;j++) cin >> a[j];
		int b = 0;
		int c = 0;
		for(int j=0;j<10;j++){
			if(b>a[j] and c>a[j]) z = false;
			if(not z) break;
			if(b>c){
				if(b>a[j]) c = a[j];
				else b = a[j];
			}
			else{
				if(c>a[j]) b = a[j];
				else c = a[j];
			}
		}
		if(z) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}