#include <iostream>
#include <algorithm>
using namespace std;

int balls[10];
int b[10];
int c[10];
int b_size;
int c_size;

bool isAscending() {
    for (int i = 0; i < b_size - 1; i++) {
        if (b[i] > b[i + 1]) {
            return false;
        }
    }
    for (int i = 0; i < c_size - 1; i++) {
        if (c[i] > c[i + 1]) {
            return false;
        }
    }
    return true;
}

bool dfs(int k, bool isB) {
    if (isB == true) {
        b[b_size++] = balls[k];
    } else {
        c[c_size++] = balls[k];
    }
    bool res = false;
    if (k == 9) {
        if (isAscending() == true) {
            res = true;
        }
    } else {
        if (dfs(k + 1, true) == true) {
            res = true;
        } else if (dfs(k + 1, false) == true) {
            res = true;
        }
    }
    if (isB == true) {
        b[--b_size] = 0;
    } else {
        c[--c_size] = 0;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        fill_n(balls, 10, 0);
        fill_n(b, 10, 0);
        fill_n(c, 10, 0);
        b_size = c_size = 0;
        for (int i = 0; i < 10; i++) {
            cin >> balls[i];
        }
        bool res = dfs(0, true);
        if (res == true) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}