#include <iostream>

using namespace std;

bool recursive(int left, int right, int* list, int index)
{
	int next = list[index];

	if(index == 9)
	{
		if(next <= left && next <= right)
			return false;
		return true;
	}

	if(left < next)
		if(recursive(next, right, list, index+1))
			return true;
	if(right < next)
		if(recursive(left, next, list, index+1))
			return true;

	return false;
}

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

	while( n-- > 0 )
	{
		int list[10];
		for(auto& n : list)
			cin >> n;

		if( recursive(0, 0, list, 0) )
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}