#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
using namespace std;

vector<int> data;
vector<int> tube_B;
vector<int> tube_C;

const int MAX = 10;

int dfs(int count){

    if (count == MAX) return 1;

    int ret = 0;

    int b = tube_B.size() - 1;
    int c = tube_C.size() - 1;

    if (data[count] > tube_B[b]){
        tube_B.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_B.pop_back();
    }

    if (data[count] > tube_C[c]){
        tube_C.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_C.pop_back();
    }

    return ret;
}

int main(void){

    int n;
    cin >> n;
    tube_B.push_back(-1);
    tube_C.push_back(-1);

    for (int i = 0; i < n; i++){
        for (int j = 0; j < 10; j++){
            int s;
            cin >> s;
            data.push_back(s);
        }

        if (dfs(0)){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }

        data.erase(data.begin(), data.end());
        tube_B.erase(tube_B.begin(), tube_B.end());
        tube_C.erase(tube_C.begin(), tube_C.end());
    }


}