#include<iostream>
#include<set>
#include<string>
#include<queue>
#include<string.h>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<stack>
#include<sstream>
using namespace std;
int num[11];
int preA, preB, x;
bool dfs(int preA,int preB,int x,int cnt) {
	if (cnt == 11) {
		return true;
	}
	if (x > preA) {
		preA = x;
		x = num[cnt + 1];
		dfs(preA, preB, x, cnt + 1);
	}
	if (x > preB) {
		preB = x;
		x = num[cnt + 1];
		dfs(preA, preB, x, cnt + 1);
	}
	if (x < preA&&x < preB) {
		return false;
	}
}
int main() {
	int t;
	cin >> t;
	while (t--) {
		for (int i = 1; i <= 10; i++)
			cin >> num[i];
		preA = num[1];
		preB = 0;
		x = num[2];
		int cnt = 2;
		if (dfs(preA, preB, x, cnt))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}
