#include <iostream>
#include <stack>

void get_input(int* arr) {
    for (int i = 0; i < 10; i++) {
        std::cin >> arr[i];
    }
}

char* solve(int* balls) {
    std::stack<int> a, b;
    a.push(0); b.push(0);

    for (int i = 0; i < 10; i++) {
        if (balls[i] > a.top() && balls[i] > b.top()) {
            if (a.top() > b.top()) {
                a.push(balls[i]);
            } else {
                b.push(balls[i]);
            }
        } else if (balls[i] > a.top() && balls[i] < b.top()) {
            a.push(balls[i]);
        } else if (balls[i] < a.top() && balls[i] > b.top()) {
            b.push(balls[i]);
        } else {
            return "NO";
        }
    }
    return "YES";
}

int main(void) {
    int balls[10];
    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        get_input(balls);
        std::cout << solve(balls) << std::endl;
    }

    return 0;
}