#include <bits/stdc++.h>
using namespace std;

int a[10];

int main() {
    int n, x, y, f;
    cin >> n;
    while (n--) {
        for (int i = 0; i < 10; i++) cin >> a[i];
        x = y = f = 0;
        for (int i = 0; i < 10; i++) {
            if (a[i] > x)
                x = a[i];
            else if (a[i] > y)
                y = a[i];
            else {
                f = 1;
                break;
            }
        }
        if (f)
            cout << "NO\n";
        else
            cout << "YES\n";
    }
}
