#include <iostream>
#include <vector>

using namespace std;
vector<int> B;
vector<int> C;

bool calc(int a[], int n, vector<int>& Vec)
{
	Vec.push_back(a[n - 1]);
	if(n == 10)
	{
		return(true);
	}
	if(B[B.size() - 1] > a[n] && C[C.size() - 1] > a[n])
	{
		return(false);
	}
	else if(B[B.size() - 1] < a[n] && C[C.size() - 1] < a[n])
	{
		return(calc(a, n + 1, B) || calc(a, n + 1, C));
	}
	else if(B[B.size() - 1] < a[n])
	{
		return(calc(a, n + 1, B));
	}
	else if(C[C.size() - 1] < a[n])
	{
		return(calc(a, n + 1, C));
	}
}

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		B.clear();
		C.clear();
		int a[10];
		for(int i = 0; i < 10; ++i)
		{
			cin >> a[i];
		}
		C.push_back(0);
		if(calc(a, 1, B))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}