#include<cstdio>
int n,j,lj,F;
int a[15],f[15];
int main()
{
	scanf("%d",&n);
	while(1)
	{
		j=0;F=0;lj=0;
		for(int i=1;i<=10;i++)
		f[i]=0,a[i]=0; 
		for(int i=1;i<=10;i++)
		scanf("%d",&a[i]);
		lj=1;
		for(int i=1;i<=10;i++)
		if(a[i+1]>a[lj]) f[lj]=1,lj=i+1;
		lj=0;
		for(int i=1;i<=10;i++)
		if(!f[i])
		{
			if(a[i]>a[lj]) lj=i;
			else {printf("NO\n");F=1;break;}
		}
		if(F) continue;
		printf("YES\n");
	}
}
/*
#include <iostream>  
  
using namespace std;  
  
const int N = 10;  
  
int main()  
{  
    int n;  
  
    cin >> n;  
    while(n--) {  
        bool ans = true;  
        int a, b=-1, c=-1;  
        for(int i=1; i<=N; i++) {  
            cin >> a;  
            if(ans) {  
                if(a > b)  
                    b = a;  
                else if(a > c)  
                    c = a;  
                else  
                    ans = false;  
            }  
        }  
  
        cout << (ans ? "YES" : "NO") << endl;  
    }  
  
    return 0;  
}  
*/