#include <bits/stdc++.h>
using namespace std;


int main(){
    
    int n;
    cin >> n;

    int b[n][10];
    

    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin >> b[i][j];
        }
    }

    bool check[n];
    for(int i=0;i<n;i++){
        check[i]=true;
    }

    for(int i=0;i<n;i++){
        vector<int> x,y;
        x.push_back(0);
        y.push_back(0);
        x.push_back(b[i][0]);
        
        
        for(int j=1;j<10;j++){
            int pa = x[x.size()-1];
            int pb = y[y.size()-1];

            int p = b[i][j];

            if(p<pa&&p<pb){
                check[i] = false;
            }else if(p<pa&&p>pb){
                y.push_back(p);
            }else if(p>pa&&p<pb){
                x.push_back(p);
            }else{
                if(pa<pb){
                    y.push_back(p);
                }else{
                    x.push_back(p);
                }
            }
        }
    }


    for(int i=0;i<n;i++){
        if(check[i]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    
    return 0;
}
