
#include <iostream>
#include <vector>
#include <string>

typedef long long ll;

using namespace std;

vector<int> balls(10);

bool flag;

void dfs(int i, int left, int right) {
    if (i == 10) {
        flag = true;
        return;
    }
    int num = balls[i];
    if (left < num) {
        dfs(i+1, num, right);
    }
    if (right < num) {
        dfs(i+1, left, num);
    }
}

void solve() {
    flag = false;
    for (int i = 0; i < 10; i++) {
        cin >> balls[i];
    }
    dfs(0, 0, 0);
    string ans = flag ? "YES": "NO";
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N = 0;
    cin >> N;

    for (int i = 0; i < N; i++) {
        solve();
    }
    return 0;
}
