#include <iostream>
#include <vector>

using namespace std;

const int BALL_NUM = 10;

static bool
judge_ball(const vector<int> &ball, const int right_head, const int left_head, const int fall_ball) {

	if (10 <= fall_ball) {
		return true;
	}

	if (right_head < ball.at(fall_ball)) {
		if (true == judge_ball(ball, ball.at(fall_ball), left_head, fall_ball + 1)) {
			return true;
		}
	}
	if(left_head < ball.at(fall_ball)) {
		if (true == judge_ball(ball, right_head, ball.at(fall_ball), fall_ball + 1)) {
			return true;
		}
	}

	return false;
}

int main(void) {
	// input
	int data_num;
	cin >> data_num;
	vector<vector<int>> ball_set(data_num, vector<int>(10,0));
	for (int i = 0; i < data_num; i++) {
		for (int j = 0; j < BALL_NUM; j ++) {
			cin >> ball_set.at(i).at(j);
		}
	}

// judge true or false
for (int i = 0; i < data_num; i ++) {
	// int right_head = ball_set.at(i).at(0)
	// int left_head = 0;
	// int fall_ball = 1;

	if (true == judge_ball(ball_set.at(i), ball_set.at(i).at(0), 0, 1)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

return 0;
}

