/*
P135
POJ 2718 Smallest Difference
*/


#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int a[10];
void read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

void solve()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO\n");
}



vector<int> L_bucket;
vector<int> R_bucket;

bool dfs2(int d){
    if(d == 10) return true;
    bool flag;
    if(L_bucket.size() == 0 || L_bucket.back() < a[d]){
        L_bucket.push_back(a[d]);
        flag = dfs2(d+1);
        L_bucket.pop_back();
    }
    if(flag) return true;
    if(R_bucket.size() == 0 || R_bucket.back() < a[d]){
        R_bucket.push_back((a[d]));
        flag = dfs2(d+1);
        R_bucket.pop_back();
    }
    if(flag) return true;
    return false;
}

void solve2()
{
    if(dfs2(0)) printf("YES\n");
    else printf("NO\n");
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve2();
    }
}