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

bool dfs(vector<int>& balls,int i, int left, int right){
    if(i >= balls.size()) return true;

    bool l = true, r = true;
    if(left > balls[i]) l = false;
    if(right > balls[i]) r = false;

    if(!l && !r) return false;

    bool ok = false;

    if(l) ok |= dfs(balls, i+1, balls[i], right);
    if(r) ok |= dfs(balls, i+1, left, balls[i]);

    return ok;
}
int main(){
    int N;
    cin >> N;
    
    for(int i=0;i<N;i++){
        vector<int> balls(10);
        for(int j=0;j<10;j++) cin >> balls[j];

        bool ans = dfs(balls, 0, 0, 0);

        if(ans) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}
