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

//定数
const int MAX_M=10;
//入力
int N;
int balls[MAX_M];

bool dfs(int i, int A, int B){
    if (i == 10){
        return true;
    }

    int value = balls[i];

    if (A >= value && B >= value){
        return false;
    }else if (A < value){
        return dfs(i+1, value, B);
    }else if (B < value){
        return dfs(i+1, A, value);
    }
}

string solve(){
    if (dfs(0, 0, 0)) return (string)"YES";
    else return (string)"NO"; 
}

int main(){
    queue<string> res;
    cin >> N;
    for (int i=0; i<N; i++){
        for (int j=0; j<10; j++){
            cin >> balls[j];
        }
        res.push(solve());
    }

    while (res.size()){
        cout << res.front() << endl;
        res.pop();
    }
    
    return 0;
}
