#include <iostream>
using namespace std;
int a[20];
int b,c;
int main(){
    int ti;
    cin>>ti;
    while(ti--){
        b=c=0;
        bool flag=1;
        for(int i=1;i<=10;i++){
            cin>>a[i];
        }
        for(int i=1;i<=10;i++){
            if(b>a[i]&&c>a[i]){
                cout<<"NO"<<endl;
                flag=0;
                break;
            }
            if(a[i]>b){
                b=a[i];
                continue;
            }
            if(a[i]>c){
                c=a[i];
                continue;
            }
        }
        if(flag){
            cout<<"YES"<<endl;
        }
    }
}
