#include <iostream>
#include <vector>
using namespace std;

bool ball(vector<int> &a,int b,int c,int n){
    //cout<<n<<" "<<b<<" "<<c<<endl;
    if(n==10){
        return true;
    }
    if(a[n]>b&&n<=9){
        b=a[n];
        return ball(a,b,c,n+1);
    }
    if(a[n]>c&&n<=9){
        c=a[n];
        return ball(a,b,c,n+1);
    }
    return false;
}


int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int tmp;
        vector<int> a;
        int b=0;
        int c=0;
        for(int j=0;j<10;j++){
            cin>>tmp;
            a.push_back(tmp);
        }
        if(ball(a,b,c,0)){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
}