//Ball

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

int main(void){
    int n;
    
    cin >> n;
    
    for(int i = 0; i < n; i++){
        
        int j;
        stack<int> Q1;
        stack<int> Q2;
        Q1.push(0);
        Q2.push(0);
        
        for( j = 0; j < 10; j++){
            int x;
            cin >> x;
            
            if(Q1.top() < x)        Q1.push(x);
            else if(Q2.top() < x)   Q2.push(x);
            else {
                cout << "NO" << endl;
                break;
            }
        }
        if(j == 10) cout << "YES" << endl;
    }
    
    return 0;
}