#include <iostream>
#include <algorithm>

using namespace std;

int a[10];

bool dfs(int B, int C, int i)
{
    if(i == 10)
        return true;
    else if(B < a[i])
        return dfs(a[i], C, i + 1);
    else if(C < a[i])
        return dfs(B, a[i], i + 1);
    
    return false;
}

int main()
{
    int N;
    cin >> N;
    while(N--)
    {
        for(int i = 0; i < 10; i++)
            cin >> a[i];
        
        cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
}