#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <sstream>
#include <cstdio>
#include <stack>
using namespace std;

// Ball(0033)
int main()
{
	int N;
	while (cin >> N) {
		for (int i = 0; i < N; ++i) {
			vector<int> ball(10);
			for (int j = 0; j < 10; ++j)
				cin >> ball[j];

			int prev = ball.front();
			ball[0] = -1;
			for (int j = 1; j < ball.size(); ++j) {
				if (prev < ball[j]) {
					prev = ball[j];
					ball[j] = -1;
				}
			}

			prev = -1;
			for (int j = 0; j < ball.size(); ++j) {
				if (prev == -1 && ball[j] != -1) {
					prev = ball[j];
					ball[j] = -1;
				} else {
					if (prev < ball[j]) {
						prev = ball[j];
						ball[j] = -1;
					}
				}
			}

			if (count(ball.begin(), ball.end(), -1) == 10)
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
	}
	return 0;
}