#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;

int a[11];
bool ok = false;

void solve(int i, vector<int> x, vector<int> y) {
    if(i >= 10) {
        bool tmp = true;

        rep(j, x.size()-1) {
            if (x[j] > x[j+1]) tmp = false;
        }
        rep(j, y.size()-1) {
            if (y[j] > y[j+1]) tmp = false;
        }

        ok |= tmp;
        return;
    }

    x.push_back(a[i]);
    solve(i+1, x, y);
    x.pop_back();
    y.push_back(a[i]);
    solve(i+1, x, y);
    y.pop_back();

    return;
}

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        rep(j, 10) cin >> a[j];
        ok = false;
        vector<int> x, y;
        solve(0, x, y);
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

