#include<stack>   //????????????
#include<iostream>
 
using namespace std;
 
int main(void){
    int n,i,data[10],ans=1;
    stack<int> right;
    stack<int> left;
 
    cin>>n;
    while(n>0){
        n--;
        cin>>data[0]>>data[1]>>data[2]>>data[3]>>data[4]>>data[5]>>data[6]>>data[7]>>data[8]>>data[9];
        right.push(data[0]);
        for(i=1;i<10;i++){
            if(right.top()<data[i])
                right.push(data[i]);
            else{
                if(left.empty())
                    left.push(data[i]);
                else{
                    if(left.top()<data[i])
                        left.push(data[i]);
                    else
                        ans=0;
                }
            }
        }
        if(ans==0) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
        while(!left.empty())
            left.pop();
        while(!right.empty())
            right.pop();
    }
 
    return 0;
}
