
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	int a = 0, b = 0;
	int in;
	int ans = 1;
	for(int i=0;i<10;i++){
		cin>> in;
		if(b < in){
			b = in;
		}else if(a < in){
			a = in;
		}else{
			ans = 0;
			break;
		}
		if(a > b) swap(a,b);
	}
	if(ans){
		cout<< "YES"<< endl;
	}else{
		cout<< "NO"<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	int n;
	cin>> n;
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}

 