#include <iostream>
#include <cstring>
using namespace std;

int seq[10];
int h1[10], h2[10];
bool dfs(int p1, int p2, int d) {
	if (d==10) return true;
	if (d==0) {
		h1[p1] = seq[d];
		return dfs(p1+1, p2, d+1);
	}
	if (h1[p1-1] < seq[d]) {
		h1[p1] = seq[d];
		return dfs(p1+1, p2, d+1);
	} else {
		if (p2==0) {
			h2[p2] = seq[d];
			return dfs(p1, p2+1, d+1);
		} else if (h2[p2-1] < seq[d]) {
			h2[p2] = seq[d];
			return dfs(p1, p2+1, d+1);
		}
	}
	return false;
}
int main() {
	int n;
	cin >> n;
	while (n--) {
		memset(seq, 0, sizeof(seq));
		memset(h1, 0, sizeof(h1));
		memset(h2, 0, sizeof(h2));
		for (int i=0; i<10; i++)
			cin >> seq[i];
		cout << (dfs(0,0,0) ? "YES" : "NO") << endl;
	}
	return 0;
}