#include <iostream>
#include <algorithm>
using namespace std;
int a[10];
int b[10];
int ball[20];
bool ans;
void dfs(int k,int ca,int cb)
{
	if(k==10)
	{
		ans = 1;
		return;
	}
	if(ball[k] > a[ca-1])
	{
		a[ca] = ball[k];
		dfs(k+1,ca+1,cb);
		a[ca] = 0;
	}
	if(ball[k] > b[cb-1])
	{
		b[cb] = ball[k];
		dfs(k+1,ca,cb+1);
		b[cb] = 0;
	}
	return;
}
int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		ans = 0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i = 0;i<10;i++)
		{
			cin >> ball[i];
		}
		dfs(0,1,1);
		if(ans == 1)
		cout << "Yes" << endl;
		else
		cout << "No" << endl;
	}
	return 0;
}