/*If I get TLE , it is good.If I get AC,it's NICE !*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=1e7+10;
const ll mod=1e9+7;
using namespace std;
typedef long long ll;
int a[11];

bool judge()
{
    for(int i=2;i<=5;i++)
    {
        if(a[i]<a[i-1]) return false;
    }
    for(int i=7;i<=10;i++)
    {
        if(a[i]<a[i-1]) return false;
    }
    return true;
}

int main(void)
{
    int t;
    cin >> t;
    while(t--)
    {
        int flag=0;
        for(int i=1;i<=10;i++)
            scanf("%d",&a[i]);
        do
        {
            if(judge())
            {
                flag=1;
                break;
            }
        }while(next_permutation(a+1,a+1+10));
        if(flag)    printf("YES\n");
        else    printf("NO\n");
    }
}