
#include <iostream>

using namespace std;

int main() {
	const bool debug = false;
	int N;
	cin >> N;

	int* balls = new int[N * 10];
	for (int i = 0; i < N * 10; i++) {
		cin >> balls[i];
	}

	for (int j = 0; j < N; j++) {
		bool isYes = true;
		int hole[2] = { 0,0 };
		for (int i = 0; i < 10; i++) {
			if (hole[0] < balls[i+j*10]) {
				hole[0] = balls[i + j * 10];
				if (debug)
					cout << "" << balls[i + j * 10] << "\n";
			} else if (hole[1] < balls[i + j * 10]) {
				hole[1] = balls[i + j * 10];
				if (debug)
					cout << "  " << balls[i + j * 10] << "\n";

			} else {
				if (debug)
					cout << "falure\n";
				isYes = false;
				break;
				
			}
		}
		cout << (isYes ? "YES" : "NO") << "\n";
	}
}
