#include <iostream>
using namespace std;

int main(){
    int i,j,k,fl;
    int a[10],b[10]={0};
    int ball[10];
    cin >> k;
    for(int g=0;g<k;g++){
        fl=0;
        for(int n=0;n<10;n++) cin >> ball[n];
        i=1;
        j=0;
        a[0] = ball[0];
        for(int n=1;n<10;n++){
            if(ball[n] < a[i] && ball[n] < b[j]){
                cout << "NO" << endl;
                fl = 0;
                break;
            }
            else if((ball[n] - a[i] > ball[i] - b[j]) && ball[n] > b[j]){
                b[j] = ball[n];
                j++;
                fl = 1;
            }
            else if((ball[n] - a[i] < ball[i] - b[j]) && ball[n] > a[i]){
                a[i] = ball[n];
                i++;
                fl = 1;
            }
        }
        if(fl == 1) cout << "YES" << endl;
    }
}