#include<iostream>
using namespace std;
#define RIGHT 1
#define LEFT 0
#define BALL 10
#define BAD 1

int main()
{
    int n;
    int num[BALL];
    int siden[BALL];
    cin >> n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<BALL;++j) {cin >> num[j]; }

        int temp,ans =0;
        unsigned int side;
        for(side=0;side<=4050;++side)
        {
            ans = 0;
            for(int j = 0;j<BALL;++j)
            {
                if(((side>>j)&1) ){siden[j] = RIGHT;}
                else {siden[j] = LEFT;}
            }
            int before = -1;
            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==RIGHT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            before = -1;

            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==LEFT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            if(ans==0)break;
        }
        if(ans==BAD) cout << "NO" << endl;
        else cout << "YES" << endl;

    }
    return 0;
}