#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

int a[20];
bool vis[20];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;cin>>T;
	while(T--){
		bool flag=false;
		for(int i=1;i<=10;i++){
			cin>>a[i];
		}
		int k[20];
		int len=1;
		k[1]=a[1];
		for(int i=2;i<=10;i++){
			if(a[i]<k[len]){
				k[++len]=a[i];
			}else{
				*upper_bound(k+1,k+1+len,a[i],greater<int>())=a[i];
			}
			if(len>2){
				flag=true;
				break;
			}
		}
		cout<<(flag?"NO\n":"YES\n");
	}
	return 0;
}
