#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
#define scai(x) scanf("%d", &x)
#define scac(x) scanf("%c", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define pri(x) printf("%d", x)
#define prc(x) printf("%c", x)
#define pri2(x,y) printf("%d %d", x, y)
#define prif(x) printf("%lf", x)
#define prif2(x, y) printf("%lf %lf", x, y)
#define mset(x, y) memset(x, y, sizeof(x))
#define fori(i, x, y) for(int i = x; i < y; i++)
#define pii pair<int, int>
#define pic pair<int, char>
#define pdd pair<double, double>
typedef long long ll;
const int N = 13;
int a[N];
int zuo[N];
int you[N];
int lc, rc;



bool solve()
{
    for(int i = 0; i < 1024; i++)
    {
        mset(zuo, 0);
        mset(you, 0);
        lc = rc = 0;
        int cnt;
        int j;
        for(j = i, cnt = 0; cnt < 10; cnt++, j >>= 1)
        {
            if(j & 1) zuo[lc++] = a[cnt];
            else you[rc++] = a[cnt];
        }
        bool flag = true;
        for(j = 1; j < lc; j++)
        {
            if(zuo[j] < zuo[j - 1]) {
                flag = 0;
                break;
            }
        }

        if(flag){
            for(j = 1; j < rc; j++){
                if(you[j] < you[j - 1]) {
                    flag = 0;
                    break;
                }
            }
        }

        if(flag) return true;
    }
    return false;
}


int main()
{
    int n;
    cin >> n;
    while(n--)
    {
        for(int i = 0; i < 10; i++)
        {
            scai(a[i]);
        }
        puts(solve()? "YES" : "NO");
    }
    return 0;
}
