#include <iostream>
using namespace std;
#define MAX_N 10

int N;
int ball[MAX_N];

int used[MAX_N];

bool dfs(int max_l, int max_r, int next) {
    if (next == MAX_N) return true;
    if(ball[next] > max_l)
        return dfs(ball[next],max_r,next+1);
    if(ball[next] > max_r) 
        return dfs(max_l,ball[next],next+1);
    return false;
}

string solve() {
   memset(used,0,sizeof(used));
   return dfs(0,0,0) ? "YES" : "NO";
}

main() {
    cin>>N;
    for(int i=0;i<N;i++) {
        for(int j=0;j<MAX_N;j++) {
            cin>>ball[j];
        }
        cout << solve() << endl;
    }
}