#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
int T,a[15],dp[15];
int main(){
	scanf("%d",&T);
	while(T--){
		memset(dp,0,sizeof(dp));
		for(int i=1;i<=10;i++) scanf("%d",&a[i]);
		for(int i=1;i<=10;i++){
			*lower_bound(dp+1,dp+11,a[i],greater<int>()) = a[i];
		}
		if(dp[3] != 0) puts("NO");
		else puts("YES");
	}
	return 0;
}
