#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#include <sstream>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int ball[10];

bool dfs(int b, int c, int k){
	if (k >= 10) return true;
	if (b > ball[k] && c > ball[k]) return false;
	if (b < ball[k] && c > ball[k]) return dfs(ball[k], c, k+1);
	if (b > ball[k] && c < ball[k]) return dfs(b, ball[k], k+1);
	return dfs(ball[k], c, k+1) || dfs(b, ball[k], k+1);
}

int main(){
    int n;
    cin >> n;
    REP(i, n){
    	REP(j, 10){
    		cin >> ball[j];
    	}
    	if (dfs(0, 0, 0)) cout << "YES" << endl;
    	else cout << "NO" << endl;
    }
}
