#include <cstdio>

const int BALL_NUMBER = 10;
bool state[1];

void back_track(int* list, int n_ptr,int left_top, int right_top) {
	// print
	//printf("ptr=%d, left=%d, right=%d\n", n_ptr, left_top, right_top);
	// find solution
	if (n_ptr == BALL_NUMBER) {
		state[0] = true;
		return;
	}
	// is ever found solution
	if (state[0]) {
		return;
	}
	// do left pattern
	if (list[n_ptr] > left_top)
		back_track(list, n_ptr + 1, list[n_ptr], right_top);
	// do right pattern
	if (list[n_ptr] > right_top)
		back_track(list, n_ptr + 1, left_top, list[n_ptr]);
	return;
}

int main(int argc, char *argv[]) {
	int dataN;
	fscanf(stdin, "%d", &dataN);
	
	for (int i = 0; i < dataN; i++) {
		int ball[10];
		state[0] = false;
		for (int j = 0; j < BALL_NUMBER; j++) {
			fscanf(stdin, "%d", &ball[j]);
		}
		// search
		back_track(ball, 0, -1, -1);
		// print result
		if (state[0])
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}