#include<iostream>

using namespace std;

int main()
{
	int n,left,right,x,ans;
	
	cin>>n;
	while(n--)
	{
		left=0,right=0,ans=1;
		
		for(int i=0;i<10;++i)
		{
			cin>>x;
			if(x>left&&x>right)
			{
				if(left>right)
					left=x;
				else
					right=x;		
			}	
			else	if(x>left)
			{
				left=x;
			}
			else 	if(x>right)
			{
				right=x;
			}
			else
			{
				ans=0;
				break;
			}
		}	
		if(ans)
			cout<<"YES\n";
		else
			cout<<"NO\n";	
	}
	
	return 0;
}
