#include <iostream>
#include <string>
using namespace std;

int main(void)
{
	int N,ball,B = 0,C = 0;
	bool ans;
	cin >> N;
	for (int i = 0; i < N; i++) {
		C = 0;
		cin >> B;
		ans = true;
		for (int j = 1;j < 10; j++) {
			cin >> ball;

			int b = ball - B;
			int c = ball - C;

			if (b < 0 && c < 0 || !ans) {
				ans = false;
				continue;
			}
			else {
				if (b > 0 && c < 0 || b > 0 && c > 0 && b < c) {
					B = ball;
				}
				else if (b < 0 && c > 0 || b > 0 && c > 0 && b > c) {
					C = ball;
				}
			}
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
	if (N == 0) {
		cout << endl;
	}
}
