//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
#include <limits>
#include <math.h>
#include <queue>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <memory>

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033

using namespace std;

// #define TEST

#ifdef TEST
static const string g_SAMPLE = R"(2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 11)";
static FILE* g_IN_FP;
static const char* g_IN_FN = "in.txt";
#define scanf(...) fscanf(g_IN_FP, __VA_ARGS__)
#endif // TEST

int main() {
#ifdef TEST
    g_IN_FP = fopen(g_IN_FN, "w");
    fwrite(g_SAMPLE.c_str(), 1, g_SAMPLE.size(), g_IN_FP);
    fclose(g_IN_FP);
    g_IN_FP = fopen(g_IN_FN, "r");
#endif // TEST
    int N;
    scanf("%d", &N);
    for (int n = 0; n < N; n++) {
        vector<int> balls;
        for (int i = 0; i < 10; i++) {
            int ball;
            scanf("%d", &ball);
            balls.push_back(ball);
        }
        bool foundGoodBits = false;
        for (int bits = 0; bits < (1 << 10); bits++) {
            if (bits > (~bits & ((1 << 10) - 1))) {
                continue;
            }
            function<bool(int)> isGoodBits = [&balls](int bits) -> bool {
                int zeroTop = 0;
                int oneTop = 0;
                for (int bit = 0; bit < 10; bit++) {
                    int* topPtr = (bits & (1 << bit)) != 0 ? &oneTop : &zeroTop;
                    if (balls[bit] <= *topPtr) {
                        return false;
                    } else {
                        *topPtr = balls[bit];
                    }
                }
                return true;
            };
            if (isGoodBits(bits)) {
                foundGoodBits = true;
                break;
            }
        }
        if (foundGoodBits) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}

