//
// Created by Tnecesoc on 2017/3/22.
//

#include <cstdio>

const int MAX_N = 10 + 10;

int a[MAX_N];

int cur1, cur2;
int b1[MAX_N], b2[MAX_N];

bool dfs(int n) {

    if (n >= 10) {
        return true;
    } else {

        if (cur1 == -1 || b1[cur1] < a[n]) {
            b1[++cur1] = a[n];
            if (dfs(n + 1)) {
                return true;
            }
        }

        if (cur2 == -1 || b2[cur2] < a[n]) {
            b2[++cur2] = a[n];
            if (dfs(n + 1)) {
                return true;
            }
        }

        return false;
    }

}

int main() {

    int n;
    scanf("%d", &n);
    while (n--) {
        for (int i = 0; i < 10; ++i) {
            scanf("%d", &a[i]);
        }

        printf("%s\n", dfs(0) ? "YES" : "NO");
    }

    return 0;
}