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

int ball[10];

bool dfs(int i = 0, int l = 0, int r = 0) {
	if(i == 10)
		return true;

	if(l < ball[i] && dfs(i + 1, ball[i], r))
		return true;

	if(r < ball[i] && dfs(i + 1, l, ball[i]))
		return true;

	return false;
}


int main() {
	cin.tie(false);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	for(int i = 0; i < n; ++i) {
		for(int i = 0; i < 10; ++i)
			cin >> ball[i];

		cout << (dfs() ? "YES" : "NO") << endl;
	}

	return EXIT_SUCCESS;
}