#include<iostream>
#include<string.h>

using namespace std;

int a[12];
int n;

bool dfs(int i, int left, int right){
    if(i == 10){
        return true;
    }

    if(a[i] > left && dfs(i + 1, a[i], right)){
        return true;
    }
    if(a[i] > right && dfs(i + 1, left, a[i])){
        return true;
    }
    return false;
}

void solve(){
    for(int i = 0; i < 10; ++i){
        cin>>a[i];
    }

    if(dfs(0, 0, 0)){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

int main(){
    cin>>n;
    while(n--){
        solve();
    }
    return 0;
}

