//0033 Ball
#include<iostream>
using namespace std;

int main(void)
{
	int n;
	cin >> n;
	while(n--)
	{
		const int N =10;
		int a[10];
		int i;
		for(i = 0; i < N; i++)
			cin >> a[i];

		int left = 0, right = 0;
		int *pMin = NULL, *pMax = NULL;
		bool result = true;
		for(i = 0; i < N; i++)
		{
			pMin = &(left < right ? left : right);
			pMax = &(left < right ? right : left);

			if(*pMin > a[i])
			{
				result = false;
				break;
			}
			else if(*pMax < a[i])
				*pMax = a[i];
			else
				*pMin = a[i];
		}
		cout << (result ? "YES" : "NO") << endl;;
	}
	return 0;
}