#include <cstdio>
#include <bitset>
#include <iostream>
using namespace std;

int a[10];

bool solve(){
        int num = 1024;
        while (num-- > 0){
                bitset<10> option(num);
                int left = 0;
                int right = 0;
                bool flag = true;
                for (int i = 0; i < 10; i++){
                        if (option[i]){
                                // right
                                if (right < a[i]){
                                        right = a[i];
                                }else{
                                        flag = false;
                                        break;
                                }
                        }else{
                                // left
                                if (left < a[i]){
                                        left = a[i];
                                }else{
                                        flag = false;
                                        break;
                                }
                        }
                }

                if (flag) break;
        }
        if (num >= 0) return true;
        else return false;
}

int main(){
        int n;
        scanf("%d", &n);
        while (n--){
                for (int i = 0; i < 10; i++){
                        scanf("%d", &a[i]);
                }
                bool ans = solve();
                if (ans) printf("YES\n");
                else printf("NO\n");
        }
        return 0;
}