#include <cstdio>
#include <iostream>

using namespace std;

int a[10], b[2][10];
int len[2];
bool ans;


void dfs(int step) {
    if(ans) return;
    if(step == 10){
        ans = true;
    }
    for(int i = 0; i < 2; ++i){
        if(len[i] == 0 || a[step] > b[i][len[i] - 1]){
            b[i][len[i]++] = a[step];
            dfs(step + 1);
            --len[i];
        }
    }
}

void solve() {
    ans = false;
    for(int i = 0; i < 10; ++i) {
        cin >> a[i];
    }
    dfs(0);
}

int main() {
    int T;
    cin >> T;
    while(T--) {
        solve();
        cout << (ans ? "YES" : "NO") << endl;
    }
    return 1;
}