#include <iostream>
#include <algorithm>

using namespace std;

int a[10];
int l[10],r[10],bl[10],br[10];
int main()
{
	int T;cin >> T;
	while(T--)
	{
		for(int i = 0;i < 10;++i)
			cin >> a[i];
		int flag = 0;
		for(int op = 0;op < 1 << 10;++op)
		{
			int lcnt = 0,rcnt = 0;
			for(int i = 0;i < 10;++i)
			{
				if(op >> i & 1)
					l[lcnt++] = a[i];
				else
					r[rcnt++] = a[i];
			}
			bool ok = 1;
			for(int i = 1;i < lcnt && ok;++i)
			{
				if(l[i] < l[i-1])
					ok = 0;
			}
			for(int i = 1;i < rcnt && ok;++i)
				if(r[i] < r[i-1])
					ok = 0;
			if(ok)
			{
				flag = 1;
				cout << "YES\n";
				break;
			}
		}
		if(!flag)
			cout << "NO\n";
	}
	return 0;
}
