#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int N;
	cin >> N;
	
	for (int i = 0; i < N; i++) {
		int a[10];
		bool success = false;
		for (int j = 0; j < 10; j++) scanf("%d", &a[j]);
		int len = 1 << 10;
		for (int j = 0; j < len; j++) {
			vector<int> u;
			vector<int> v;
			for (int k = 0; k < 10; k++) {
				if (j >> k & 1) u.push_back(a[k]);
				else v.push_back(a[k]);
			}
			
			bool x = is_sorted(u.begin(), u.end());
			bool y = is_sorted(v.begin(), v.end());
			if (x && y) {
				printf("YES\n");
				success = true;
				break;
			}
		}
		
		if (!success) {
			printf("NO\n");
		}
	}
}