#include <cstdio>
using namespace std;
int n;
int a[11];
int main() {
    scanf("%d", &n);
    for (int t = 0; t < n; ++t) {
        int l = 0, r = 0;
        for (int i = 0; i < 10; ++i) scanf("%d", &a[i]);
        bool flag=false;
        for (int i = 0; i < 10; ++i) {
            if (r > l) {
                if (a[i] > r) r = a[i];
                else if (a[i] > l) l = a[i];
                else flag=true;
            } else {
                if (a[i] > l) l = a[i];
                else if (a[i] > r) r = a[i];
                else flag=true;
            }
        }
        if (flag) printf("NO");
        else printf("YES");

    }
    return 0;
}

