#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define Vi vector<int>
#define Vl vector<long long>
#define pb(a) push_back(a)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct edge{int to,cost;};
struct pos{
	int x,y;
};

int main() {

	int n;
	cin>>n;
	rep(i,n){
		ll a=0,b=0,f=0;
		rep(j,10){
			ll x;
			cin>>x;
			if(f==1)continue;
			if(x<a&&x<b)f=1;
			else if(x>max(a,b)){
				if(a>b)a=x;
				else b=x;
			}else{
				if(a>b)b=x;
				else a=x;
			}
		}
		if(f==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

	return 0;
}

