#include <iostream>
#include <cstdint>

int main()
{
	std::uint32_t n;
	std::cin >> n;
	for (std::uint32_t i = 0; i < n; ++i) {
		bool is_collect_rank = true;
		std::uint16_t b = 0, c = 0;
		for (std::uint16_t j = 0; j < 10; ++j) {
			std::uint16_t num;
			std::cin >> num;
			if (b > num && c > num) {
				is_collect_rank = false;
			}
			else if (b < num && c > num) {
				b = num;
			}
			else if (b > num && c < num) {
				c = num;
			}
			else {
				(b > c ? b : c) = num;
			}
		}
		std::cout << (is_collect_rank ? "YES" : "NO") << std::endl;
	}
	return 0;
}