#include<iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int ni = 0; ni < n; ni++) {
		int a[10], b[11], c[11];
		int pb = 0, pc = 0;
		int ok = 1;
		b[0] = c[0] = 0;
		for (int i = 0; i < 10; i++) {
			cin >> a[i];
			if (a[i] > b[pb]) {
				b[++pb] = a[i];
			}
			else if (a[i] > c[pc]) {
				c[++pc] = a[i];
			}
			else {
				ok = 0;
			}
		}
		if (ok) cout << "YES\n";
		else cout << "NO\n";
	}
}
