#include<iostream>
int main()
{
	int N;
	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		int b_back = 0, c_back = 0;
		bool is_OK = true;
		for (int j = 0; j < 10; j++)
		{
			int num;
			std::cin >> num;
			if (num < b_back && num < c_back)
			{
				is_OK = false;
				break;
			}
			else if (num > b_back && num < c_back)
			{
				b_back = num;
			}
			else if (num < b_back && num > c_back)
			{
				c_back = num;
			}
			else
			{
				if (b_back > c_back)
				{
					b_back = num;
				}
				else
				{
					c_back = num;
				}
			}
		}
		std::cout << (is_OK ? "YES" : "NO") << std::endl;
	}
	return 0;
}
