#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define PII pair<int, int>
using namespace std;
const int MAXN = 40;

int p[10], pre1, pre2;

bool dfs(int pos) {
    if (pos >= 10) return true;
    int tmp1 = pre1, tmp2 = pre2;

    if (p[pos] > pre1) {
        pre1 = p[pos];
        if (dfs(pos + 1)) return true;
        pre1 = tmp1;
    }

    if (p[pos] > pre2) {
        pre2 = p[pos];
        if (dfs(pos + 1)) return true;
        pre2 = tmp2;
    }

    return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int T;
    cin >> T;
    for (int t = 0; t < T; t++) {
        for (int i = 0; i < 10; i++) cin >> p[i];
        pre1 = pre2 = -1;
        if (dfs(0)) cout << "YES\n";
        else cout << "NO\n";
    }
}

