#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int a[11];
bool dfs(int i, int b, int c) {
    if (i == 10) return true;
    if (b < a[i]) {
        if (dfs(i + 1, a[i], c)) return true;
    }
    if (c < a[i]) {
        if (dfs(i + 1, b, a[i])) return true;
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        rep(j, 10) cin >> a[j];
        cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
}