#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

string solve(){
    vector<int> a(10,0);
    rep(i,10){
        cin>>a[i];
    }
    for(int bit = 0; bit < (1<<11);++bit){
        vector<int> bv,cv;
        int b=0,c=0;
        bool is = true;
        rep(i,10){
            if(bit & (1<<i)){
                if(b<a[i]) b = a[i];
                else is = false;
            }else{
               if(c<a[i])c = a[i];
               else is = false;
            }
        }
        if(is) return "YES";
    }
    return "NO";

}

int main(){
    int n;
    cin >> n;
    rep(i,n){
        cout<<solve()<<endl;
    }

    return 0;
}
