#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

bool dfs(int depth,vi ball,stack<int> B,stack<int> C){
	if (depth == 10){
		return true;
	}
	bool ret,retB,retC;
	int A = ball[depth];
	
	if (B.top() < A){
		B.push(A);
		retB = dfs(depth + 1,ball,B,C);
		B.pop();
	}else{
		retB = false;
	}
	if (C.top() < A){
		C.push(A);
		retC = dfs(depth + 1,ball,B,C);
		C.pop();
	}else{
		retC = false;
	}

	if (retB or retC){
		ret = true;
	}else{
		ret = false;
	}

	return ret;

}

int main() {
	
	int n; cin >> n;

	for (int i = 0; i < n; i++){
		vi ball(10);
		stack<int> B,C;
		B.push(-1);
		C.push(-1);
		int num;
		for (int j = 0; j < 10; j++){
			cin >> ball[j];
		}

		if (dfs(0,ball,B,C)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}