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

const int N = 15;
int arr[N];
bool flag;


void dfs(int left, int right, int cur){
    if (flag) return;

    if (cur == 10){
        flag = true;
        return;
    }

    if (left < arr[cur]){
        dfs(arr[cur], right, cur + 1);
    }
    if (right < arr[cur]){
        dfs(left, arr[cur], cur + 1);
    }
}

int main(){
    int t; cin >> t;
    while (t--){
        for (int i = 0; i < 10; ++ i) cin >> arr[i];
        flag = false;

        int left(0), right(0);

        dfs(left, right, 0);
        if (flag) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}
