#include<iostream>
#include<stack>
#include<queue>
using namespace std;

int main(){
    stack<int> b, c;
    int a[10];
    bool which[11];
    int data[11];
    int index;
    int n, m, A;
    int i, j;
    cin >> n;
    for(i=0;i<n;i++){
        index = 0;
        for(j=0;j<10;j++){
            cin >> m;
            a[j] = m;
            data[j+1] = 0;
        }
        b.push(0);
        c.push(0);
        while(index>=0){
            A = a[index];
            if(b.top() < A && (data[A] != 1 && data[A] != 3)){
                b.push(A);
                data[A] += 1;
                which[A] = true;
            }else if(c.top() < A && (data[A] != 2 && data[A] != 3)){
                c.push(A);
                data[A] += 2;
                which[A] = false;
            }else{
                index--;
                if(index < 0){
                    break;
                }else if(which[a[index]]){
                    b.pop();
                }else{
                    c.pop();
                }
                continue;
            }
            index++;
            if(index > 9){
                cout << "YES" << endl;
                break;
            }
        }
        if(index < 0){
            cout << "NO" << endl;
        }
    }
}