#include <stdio.h>
#include <iostream>

using namespace std;

int n;
int data[11];
int l,r;
bool fla;

void solve(){
    scanf("%d",&n);
    while(n--){

        for(int i = 1; i <= 10; i++){
            scanf("%d",&data[i]);
        }

        l = 0;
        r = 0;
        fla = true;

        for(int i = 1; i <= 10; i++){
            if(data[i] > l && data[i] > r){
                if(l > r){
                    l = data[i];
                }else{
                    r = data[i];
                }
            }else if(data[i] > l && data[i] < r){
                l = data[i];
            }else if(data[i] > r && data[i] < l){
                r = data[i];
            }else{
                fla = false;
                break;
            }
        }

        if(fla){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }

    }
}

int main(void){

    solve();

    return 0;
}
