import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
import std.string;
void main() {
        int n=to!int(readln().strip());
        for(int i=0;i<n;i++){
                auto bs=readln().split().map!(to!int)().array();
                int s1=-1,s2=-1;
                bool flag = true;
                for(int j=0;j<10;j++){
                        if(s1<bs[j]&&bs[j]-s1<bs[j]-s2)s1=bs[j];
                        else if(s2<bs[j]&&bs[j]-s1>bs[j]-s2)s2=bs[j];
                        else if(s1<bs[j]) s1=bs[j];
                        else if(s2<bs[j]) s2=bs[j];
                        else {flag=false;break;}
                }
                if(flag) writeln("YES");
                else writeln("NO");
        }
}