#include <iostream>
#include <algorithm>

using namespace std;

int ball[10];

bool dfs(int B, int C, int cnt){
    if(cnt == 10){
        return true;
    }
    if(B < ball[cnt]){
        return dfs(ball[cnt], C, cnt + 1);
    }
    if(C < ball[cnt]){
        return dfs(B, ball[cnt], cnt + 1);
    }
    if(B > ball[cnt] && C > ball[cnt]){
        return false;
    }
}

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 10; j++)
            cin >> ball[i];

        if(dfs(0, 0, 0)) 
            cout << "YES" << endl;
        else 
            cout << "NO" << endl;
    }
}