#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>

using namespace std;

int n, a[10];

bool dfs(int depth, int b, int c) {
    if (depth == 10)
        return true;
    bool ret = false;
    if (a[depth] > b) {
        ret = ret || dfs(depth + 1, a[depth], c);
    }
    if (a[depth] > c) {
        ret = ret || dfs(depth + 1, b, a[depth]);
    }
    return ret;
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> a[j];
        }
        if (dfs(0, 0, 0))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}
