#include<iostream>
#include<vector>
#include<algorithm>

int main()
{
	int n,a;

	std::cin >> n;

	std::vector<int> ball;

	for(int i=0; i<n; ++i)
	{
		for(int i=0; i<10; ++i)
		{
			std::cin >> a;

			ball.push_back(a);
		}
		
		int right=-1,left=-1;

		right = ball[0];

		bool flg1 = 1;

		bool rightOK;

		bool leftOK;

		for(int i=1; i<10; ++i)
		{
			rightOK = ball[i]>right;

			leftOK = (ball[i]>left || left==-1);

			if(rightOK && leftOK)
			{
				if(right>left)
				{
					right = ball[i];
				}
				else
				{
					left = ball[i];
				}
			}
			else if(rightOK)
			{
				right =  ball[i];
			}
			else if(leftOK)
			{
				left = ball[i];
			}
			else
			{
				flg1 = 0;

				break;
			}
		}

		std::cout << (flg1 ? "YES\n" : "NO\n");

		ball.clear();
	}
}