/*#include<iostream>
#include<stack>
using namespace std;
int source[15];
int main()
{
    int x;
    cin>>x;
    while(x--)
    {
        stack<int>a;
        stack<int>b;
        a.push(0);
        b.push(0);
        for(int k=0;k<10;k++)
            cin>>source[k];
            int i;
            bool flag=0;
        for(i=0;i<10;i++)
        {
            if(source[i]<a.top()&&source[i]<b.top())
               {
                   flag=1;
                    break;
               }
             else if(source[i]>a.top()&&source[i]<b.top())
                    a.push(source[i]);
             else if(source[i]>b.top()&&source[i]<a.top())
                    b.push(source[i]);
                    else
                    {

                    if(a.top()>=b.top())
                        a.push(source[i]);
                    else
                        b.push(source[i]);
                    }
        }
                if(flag)
                cout<<"NO"<<endl;
                else
                    cout<<"YES"<<endl;
    }
    return 0;
}*/
#include<iostream>
using namespace std;
int a[15];
int flag;
void dfs(int x,int l,int r)
{
    if(flag)
        return ;
    if(x==10)
    {
        return ;
    }
    else
    {
        if(a[x]>l)
           dfs(x+1,a[x],r);
        else if(a[x]>r)
            dfs(x+1,l,a[x]);
        else
        {
            flag=1;
            return ;
        }
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        for(int i=0;i<10;i++)
            cin>>a[i];
            flag=0;
            dfs(0,0,0);
            if(flag)
                cout<<"NO"<<endl;
            else
                cout<<"YES"<<endl;
    }
    return 0;
}

