#include <iostream>
using namespace std;
const int N = 10;
int main(){
    int n,i,ans,a,b,c;;
    cin >> n;
    while(n--) {
    	ans=1;
    	b=c=-1;
        for(i=0;i<10;i++){
        	cin>>a;
        	if(a>b)
        		b=a;
        	else if(a>c)
        		c=a;
        	else
        		ans=0;
		}
		if(ans) puts("YES");
    	else puts("NO");
    }
}
