#include <iostream>
#include <vector>

using namespace std;

bool solve(vector<int> balls, vector<int> &b,vector<int> &c, int index) {
    
    if (index >= 10) return true;
    if (b.back() < balls[index]) {
        b.push_back(balls[index]);
        index++;
        return solve(balls, b, c, index);
    }
    if (c.back() < balls[index]) {
        c.push_back(balls[index]);
        index++;
        return solve(balls, b, c, index);
    }
    return false;
}

int main(){
    int N;
    cin >> N;
    bool flag;
    vector<vector<int> > balls(N, vector<int>(10));
    
    for (int j = 0; j < N; j++) {
        for (int i = 0; i < 10; i++) {
            cin >> balls[j][i];
        }
    }
    for (int j = 0; j < N; j++) {
        vector<int> b, c;
        b.push_back(0);
        c.push_back(0);
        flag = solve(balls[j], b, c, 0);
        if (flag) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    
  return 0;
}

