#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int num1[12];
int num2[12];
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        memset(num1,0,sizeof(num1));
        memset(num2,0,sizeof(num2));
        int num;
        int ans1=1,ans2=0;
        cin>>num;
        num1[0]=num;
        for(int i=1;i<=9;i++)
        {
            cin>>num;
            if(num>num1[ans1-1])
                num1[ans1++]=num;
            else
            {
                num2[ans2++]=num;
            }
        }
        /*for(int i=0;i<ans1;i++)
            cout<<num1[i]<<" ";
        cout<<endl;
        for(int i=0;i<ans2;i++)
            cout<<num2[i]<<" ";
        cout<<endl;*/
        int flag=0;
        for(int i=1;i<ans2;i++)
        {
            if(num2[i]<num2[i-1])
            {
                flag=1;
                break;
            }
        }
        if(flag)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}
