#include<iostream>
using namespace std;

int N;
int b[10];
bool res;

bool dfs(int n, int b1, int b2) {
    if (n == 9) { 
        if (b[n] > b1 || b[n] > b2) return true;
        return false;
    }
    if ((b[n] > b1 && dfs(n+1,b[n],b2)) ||
        (b[n] > b2 && dfs(n+1,b1,b[n]))) {
        return true;
    } else {
        return false;
    }
}

void solve() {
    res = dfs(1,b[0],-1);
    if (res) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> b[j];  
        }
        solve();
    }
}
