#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<int(n);i++)
int a[10];
int main(){
	int t;
	cin>>t;
	while(t--){
		forn(i,10) cin>>a[i];
		int fi=0,se=0;
		bool b=true;
		forn(i,10){
			if(fi<a[i]&&se<a[i]){
				if(fi<=se) se=a[i];
				else fi=a[i];
			}
			else if(fi<a[i]) fi=a[i];
			else if(se<a[i]) se=a[i];
			else{
				b=false;
				break;
			}
		}
		if(b) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}