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

bool res = false;
int a[10];

void dfs(int i, int l, int r) {
    if (i >= 10) {
        res = true;
        return;
    }
    else {
        if (a[i] > l) dfs(i + 1, a[i], r);
        if (a[i] > r) dfs(i + 1, l, a[i]);
    }
}

int main() {
    int T;
    cin >> T;
    for (int i = 0; i < T; ++i) {
        for (int j = 0; j < 10; ++j) cin >> a[j];
        res = false;
        dfs(0, 0, 0);
        cout << (res?"YES":"NO") << endl;
    }
    return 0;
}
