#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{	
	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int left = 0, right = 0;
		int ball[10];

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

		for (int j = 0; j < 10; j++)
		{
			if (left < ball[j] && right < ball[j])
			{
				if (right < left)
				{
					left = ball[j];
				}
				else
				{
					right = ball[j];
				}
			}
			else if (left < ball[j])
				left = ball[j];
			else if (right < ball[j])
				right = ball[j];
			else
			{
				cout << "NO" << endl;
				break;
			}
		}

		if (right == ball[9] || left == ball[9]) cout << "YES" << endl;
	}

	return 0;
}

