//
// Create by 神舟 on 2015-02-20
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <set>
#include <vector>
using namespace std;

#define CLR(x) memset(x,0,sizeof x)
#define ll long long
#define inf 0x3f3f3f3f
const int maxn=1e1+5;
const int MOD=5e5+5;
int n;
int dp[maxn];
int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	scanf("%d",&n);
	while(n--){
        CLR(dp);
        int num;
        int maxlen=0;
        dp[maxlen]=inf;
        int flag=1;
        for(int i=1;i<11;i++){
            scanf("%d",&num);
            if(maxlen>2) flag=0;
            if(num<=dp[maxlen])
                dp[++maxlen]=num;
            else{
                int l=1,r=maxlen;
                while(l<=r){
                    int mid=l+(r-l)/2;
                    if(dp[mid]>num) l=mid+1;
                    else r=mid-1;
                }
                dp[l-1]=num;
            }
        }
        if(flag) printf("YES\n");
        else printf("NO\n");
	}

	return 0;
}