#include <cstdio>

using namespace std;

int n;
int t[15], t1[15], t2[15];

bool yes;
void dfs(int n, int t1[], int num, int t2[])
{
    if(n == 10)
    {
        bool zen1=true, zen2 = true;
        for(int i=1; i<num; i++) if(t1[i]<t1[i-1]) zen1 = false;
        for(int i=1; i<10-num; i++) if(t2[i]<t2[i-1]) zen2 = false;
        if(zen1 && zen2) yes = true;
        return ;
    }
    t1[n+1] = t[n+1];
    dfs(n+1, t1, num+1, t2);
    t2[n+1] = t[n+1];
    dfs(n+1, t1, num, t2);
}

int main()
{
    scanf("%d", &n);
    while(n--)
    {
        for(int i=0; i<10; i++)
            scanf("%d", &t[i]);
        yes = false;
        dfs(0, t1, 0, t2);
        if(yes)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}