#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define B 0
#define C 1

int main()
{
    int n;
    cin >> n;
    while(n>0)
    {
        int a[10],b[10],c[10];
        rep(i,10)cin >> a[i];
        int bnum=0,cnum=0;
        int t;
        int side = B;
        int res =1;
        b[0] =a[9];
        bnum = 1;
        for(int i = 8;i!=-1;i--)
        {
            if(side == B)
            {
                if(b[bnum-1]<a[i])
                {
                    side=C;
                    if((cnum!=0)&&(c[cnum]<a[i])){res = 0;break;}
                    else{cnum++; c[cnum]=a[i]; }
                }
                else
                {
                    bnum++;
                    b[bnum] = a[i];
                }
            }
            else
            {
                if(c[cnum-1]<a[i]){
                    side = B;
                    if(b[bnum]<a[i]){res = 0;break;}
                    else{bnum++; b[bnum] = a[i];}
                }
                else
                {
                    cnum++;
                    c[cnum]=a[i];
                }
            }
        }
        if(res==1)cout <<"YES" << endl;
        else cout << "NO" << endl;
        n--;
    }
    return 0;
}