#include <iostream>

using namespace std;

bool s( int ord[], int const i, int const a = -1, int const b = -1 )
{
    if ( i >= 10 )
        return true;
    
    if ( ord[i] <= a && ord[i] <= b )
        return false;

    if ( ord[i] > a )
        return s( ord, i+1, ord[i], b );

    if ( ord[i] > b )
        return s( ord, i+1, a, ord[i] );

    return true;
}

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 ) ? "YES" : "NO" ) << endl;
    }
}