
#include <algorithm>
#include <iostream>
#include <string.h>

using namespace std;

#define int_ int64_t
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define lb long double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

ll n,a[15];
vector<ll> v1,v2;
bool ans=false;

void dfs(ll idx) {
    if (idx>10) {
        ans=true;
        return;
    }
    if (v1.empty()||a[idx]>v1.back()) {
        v1.pb(a[idx]);
        dfs(idx+1);
        v1.pop_back();
    }
    if (v2.empty()||a[idx]>v2.back()) {
        v2.pb(a[idx]);
        dfs(idx+1);
        v2.pop_back();
    }
}

int main()
{
    scanf("%lld",&n);
    for (ll i=1;i<=n;i++) {
        for (ll j=1;j<=10;j++) scanf("%lld",a+j);
        ans=false;
        dfs(1);
        if (ans) printf("YES\n");
        else printf("NO\n");
    }
}
