//#include <bits/stdc++.h>

#include <cstdio>
#include <stack>

using namespace std;

const int MAX_W = 103, MAX_H = 103;

int num[10];
bool res = false;
stack<int> left, right;

void dfs(int i){
    if(i == 10){
        res = true;

        return;
    }

    if(num[i] > left.top()) {
        left.push(num[i]);
        dfs(i+1);
        left.pop();
    }

    if(num[i] > right.top()){
        right.push(num[i]);
        dfs(i+1);
        right.pop();
    }
}

void solve(){

    left.push(0);
    right.push(0);
    dfs(0);
    if(res) printf("YES\n");
    else printf("NO\n");
}

int main(){
    int T;
    scanf("%d", &T);
    while(T--){

        for(int i = 0;i < 10;i++){
            scanf("%d", &num[i]);
        }
        res = false;
        solve();
    }
    return 0;
}

/*
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
 */
