#include<iostream>
#include<queue>
#include<stack>
using namespace std;
int main()
{
	int n;
	cin>>n;
	stack<int>q;
	stack<int>p;
	while(n--){
		
		q.push(0);
		p.push(0);
		int f=1;
		for(int i=1;i<=10;i++)
		{
			int t;
			cin>>t;
			if(p.top()<t)
			p.push(t);
			else if(q.top()<t)
			q.push(t);
			else{
				f=0;
			}
		}
		if(f==0)
		cout<<"NO"<<endl;
		else
		cout<<"YES"<<endl;
		while(!q.empty())
		q.pop();
		while(!p.empty())
		p.pop();
	
	}
 } 
