#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)

int a[11];
bool ans;

int main()
{
	int n; cin >> n;
	REP(l, n)
	{
		REP(i, 10) cin >> a[i];
		int b = 0; int c = 0;
		REP(i, 10)
		{

			if (a[i] < b&&a[i] < c) goto miss;
			else if (a[i] > b&& a[i] > c)
			{
				if (b > c) b = a[i];
				else c = a[i];
			}
			else if (a[i] > b&& a[i] < c) b = a[i];
			else if (a[i] < b&& a[i] > c) c = a[i];
		}
		cout << "YES" << endl;
		continue;
	miss:
		cout << "NO" << endl;
	}
	return 0;
}