#include<iostream>
using namespace std;

int num[10];
bool chack;

void solve(int R, int L, int i){
    if(i==10) chack = true;
    if(chack == true) return;
    if(num[i]>R) solve(num[i], L, i+1);
    if(num[i]>L) solve(R, num[i], i+1);
    return;
}
int main(void){
    int N;
    cin >> N;
    while(N>0){
        chack = false;
        for(int i=0; i<10; i++)
            cin >> num[i];
        solve(0,0,0);
        if(chack)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
        N--;
    }
}

