#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define INF INT_MAX/3
#define vc vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define ll long long
#define eps 1e-14
int dx[] = { 1,-1,0,0,0 };
int dy[] = { 0,0,1,-1,0 };


int x[10];
vc ans;
void solve() {
	int left, r;
	left = x[0];
	r = 0;
	//?????¨?????§??§??????????????§?????¶??????????????´???????????\??????
	for (int i = 1; i < 10; i++) {
		//???????????¶??????????????????
		if (left > x[i] && r > x[i]) {
			//cout << "NO" << endl;
			ans.push_back(0);
			return;
		}
		//?????????????????¶????????????
		if (x[i] < left && r < x[i]){
			r = x[i];
			continue;
		}
		else if (x[i] < r&&left < x[i]) {
			left = x[i];
			continue;
		}
		else { //???????????????????????´???
			if (r < left) {
				left = x[i];
				continue;
			}
			else {
				r = x[i];
				continue;
			}
		}
		
	}
	//cout << "Yes" << endl;
	ans.push_back(1);
}

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		REP(j, 10)
			cin >> x[j];
		solve();
	}
	for (int i = 0; i < ans.size(); i++) {
		if (ans[i] == 0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
	}
	return 0;
}