#include <iostream>

using namespace std;

int ball[10];

bool dfs (int n, int a, int b)
{
    if (n==10) return true; //no ball left
    if (ball[n]>a) return dfs(n+1,ball[n],b); //search further
    if (ball[n]>b) return dfs(n+1,a,ball[n]);
    return false;
}

int main()
{
    //DFS for the first time
    int n;
    cin>>n;
    bool ret[n];
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<10; j++) cin>>ball[j];
        ret[i]=dfs(0,0,0);
    }
    for (int i=0; i<n; i++)
    {
        if (ret[i]) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

