#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

vector<int> v(10);

int l,r;
int flag;

void dfs(int d){

    if(d==10){
        flag=1;
        return;
    }

    if(flag) return;

    int x = v[d];

    if(x>l){

        int tmp = l;
        l=x;
        dfs(d+1);
        l=tmp;

    }

    if(flag) return;

    if(x>r){

        int tmp = r;
        r=x;
        dfs(d+1);
        r = tmp;

    }

}

int main(){

    int N;

    cin >> N;

    for(int t=0;t<N;++t){

        for(int i=0;i<10;++i)cin >> v[i];

        l = r = flag = 0;

        dfs(0);

        if(flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;

    }

    return 0;

}