#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
 
#define REP(i,b,n) for(int i=b;i<n;++i)
#define REPR(i,b,n) for(int i=n-1;i>=b;--i)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PI acos(-1.0)

using namespace std;

static const double EPS = 1e-9;
typedef pair<int, int> pii;
typedef long long ll;

int ball[10];

bool issorted(vector<int> v){

	if(v.size() < 2)
		return true;
	
	for(int i = 0 ; i < v.size()-1; ++i){
	
		if(v[i] > v[i+1])
			return false;
	}
	
	return true;
}

string solve(){
	
	for(int i=0; i < (1<<10); ++i){
		
		vector<int> lft, rgt;
		
		for(int j=0; j<10; ++j){
			
			if(BIT(i,j))
				lft.push_back(ball[j]);
			else
				rgt.push_back(ball[j]);
		}
		
		if(issorted(lft)&& issorted(rgt)){
			return "YES";
		}
	}
	
	return "NO";
}		

int main(){
		
	int n;
	cin >> n;
	
	for(int k=0; k<n; ++k){
	
		for(int i=0; i<10; ++i){
			cin >> ball[i];
		}
		
		cout << solve() << endl;
	}
	
	return 0;
}