#include <iostream>
int a[15];
bool dfs(int prev_b , int prev_c , int p){
    if(p == 10){
        return true;
    }
    bool tf = false;
    if(a[p] > prev_b){
        tf = dfs(a[p] , prev_c , p + 1);
    }
    if(tf){
        return true;
    }
    if(a[p] > prev_c){
        tf = dfs(prev_b , a[p] , p + 1);
    }
    return tf;
}
int main(){
    int n;
    std::cin >> n;
    while(n--){
        for(int i = 0;i < 10;i++){
            std::cin >> a[i];
        }
        if(dfs(-1 , -1 , 0)){
            std::cout << "YES\n";
        }else{
            std::cout << "NO\n";
        }
    }
}
