#include <iostream>
#include <cstdio>

bool solve(const int* values, int count, int top1, int top2)
{
	return (count == 0)
		|| (*values > top1 && solve(values + 1, count - 1, *values, top2))
		|| (*values > top2 && solve(values + 1, count - 1, top1, *values));
}


int main()
{
	int count = 0;
	std::cin >> count;

	for (int i = 0; i < count; ++i) {
		int values[10] = {};
		for (int j = 0; j < 10; ++j) {
			std::cin >> values[j];
		}
		if (solve(values, 10, 0, 0)) {
			std::cout << "YES\n";
		} else {
			std::cout << "NO\n";
		}
	}

	return 0;
}