#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>


int N;
int a[100];
int left[100], right[100], flag;
int main()
{
    scanf("%d", &N);

   while(N--){

        for(int j = 0; j < 10; j++) scanf("%d", &a[j]);

        for(int j = 0; j < 1<<10; j++)
        {
            int l = 0, r = 0;
            flag = 1;
            for(int k = 1, x = 0; k < 1<<10; k<<=1, x++)
            {
                if(j & k)  left[l++] = a[x];
                else   right[r++] = a[x];

                if((l >= 2 && left[l-1] <= left[l-2]) ||(r >= 2 && right[r-1] <= right[r-2]))
                {
                    flag = 0;
                    break;
                }
            }

            if(flag) break;

        }
        if(flag) printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}