#include <iostream>

using namespace std;

bool s( int ord[], int const i, int const bef = -1 )
{
    if ( i > 10 )
        return true;

    if ( bef != -1 && bef > ord[i] )
        return false;

    return s( ord, i+1, ord[i] ) || s( ord, i+2, ord[i] );
}

int main()
{
    int n;
    cin >> n;

    for( int iii=0; iii<n; ++iii ) {
        int ord[10];
        for( int i=0; i<10; ++i )
            cin >> ord[i];

        cout << ( s( ord, 0 ) || s( ord, 1 ) ? "YES" : "NO" ) << endl;
    }
}