#include <iostream>
// #include <algorithm>

using namespace std;

bool dfs(int i, int left, int right, int* balls) {
    if(i == 10)
        return true;

    if(balls[i] > left && dfs(i+1, balls[i], right, balls))
        return true;

    if(balls[i] > right && dfs(i+1, left, balls[i], balls))
        return true;

    return false;
}

int main() {
    int N;
    int balls[10];
    cin >> N;
    while(N-- > 0) {
        for(int i = 0; i < 10; i++)
            cin >> balls[i];

        if(dfs(1, balls[0], 0, balls))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}
