#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<climits>
#include<algorithm>
#include<functional>
#include<iomanip>
#define LL long long
using namespace std;

int T,a[15];

int main(void){
    scanf("%d",&T);
    while(T--){
        int i;
        for(i=1;i<=10;i++) scanf("%d",&a[i]);
        bool can=true;
        int l=0,r=0;
        for(i=1;i<=10;i++){
            if(a[i]<l && a[i]<r){
                can=false;
                break;
            }
            if(l<r){
                if(a[i]>r) r=a[i];
                else l=a[i];
            }
            else{
                if(a[i]>l) l=a[i];
                else r=a[i];
            }
        }
        if(can) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

