#include <cstdio>
#include <algorithm>

using namespace std;

const int BALL_NUM = 10;

long n;

bool IsLeft(int num, int left, int right) {
    if (left > num) { return false; }
    if (left > right || right > num) { return true; }
    else { return false; }
}

int main() {
    scanf("%ld", &n);
    for (int i = 0; i < n; i++) {
        int b, left = 0, right = 0;
        bool flag = true;
        for (int j = 0; j < BALL_NUM; j++) {
            scanf("%d", &b);
            if (b < min(left, right)) {
                flag = false;
                break;
            }
            if (IsLeft(b, left, right)) { left = b; }
            else { right = b; }
        }
        if (flag) { printf("%s\n", "YES"); }
        else { printf("%s\n", "NO"); }
    }

    return 0;
}