#include <iostream>
using namespace std;
int N;
int V[10];

int dfs(int a, int b, int d) {
    if(d==10) return 1;
    int atry = 0, btry = 0;
    if(a < V[d]) atry = dfs(V[d], b, d+1);
    if(b < V[d]) btry = dfs(a, V[d], d+1);
    if(atry == 0 && btry == 0) return 0;
}

int main() {
    cin >> N;
    for(int i=0; i<N; i++) {
        for(int j=0; j<10; j++) cin >> V[j];
        int res = dfs(0,0,0);
        if(res) cout << "YES" << endl;
        else cout << "NO" << endl; 
    }
}
