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

int n, N[15];

int main() {
	cin >> n;
	int a = 0, b = 0;
	while (n--) {
		bool t = true;
		a = 0, b = 0;
		for (int i = 0; i < 10; i++) {
			cin >> N[i];
		}
		for (int i = 0; i < 10; i++) {
			if (a > N[i] && b > N[i]) {
				cout << "NO" << endl;
				t = false;
				break;
			} else if (a < N[i]) {
				if (a < b) {
					b = N[i];
				} else {
					a = N[i];
				}
			} else {
				b = N[i];
			}
		}
		if(t) {
			cout << "YES" << endl;
		}
	}
	return 0;
}