#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>

using namespace std;

int main()
{
	int T;
	cin >> T;
	int a[11];
	bool vis[11];
	while (T--)
	{
		bool flag = 1;
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= 10; i++)
			scanf("%d", &a[i]);
		stack<int> s;
		s.push(a[1]);
		vis[1] = 1;
		for (int i = 2; i <= 10; i++)
		{
			if (a[i] > s.top())
			{
				s.push(a[i]);
				vis[i] = 1;
			}
		}
		int temp,i;
		for ( i = 2; i <= 10; i++)
		{
			if (vis[i] == 0)
			{
				temp = a[i];
				break;
			}
		}
		i++;
		for (i; i <= 10; i++)
		{
			if (vis[i] == 0)
			{
				if (a[i] >= temp)
				{
					temp = vis[i];
				}
				else if (a[i] < temp)
				{
					flag = 0;
					break;
				}
			}
		}
		if (flag == 1)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}