#include "bits/stdc++.h"
using namespace std;

long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}
long long int lca(long long int l, long long int r) {
	return l / gcd(l, r)*r;
}
int getans(const int num, const int rest) {
	if (rest) {
		int ans = 0;
		for (int i = 0; i <= 9; ++i) {
			if (num >= i) {
				ans += getans(num - i, rest - 1);
			}
		}
		return ans;
	}
	else {
		return num == 0;
	}
}
int main() {
	int N;
	cin >> N;
	while (N--) {
		vector<int>nums(10);
		bool ok = false;
		for (int i = 0; i < 10; ++i)cin >> nums[i];
		for (int j = 0; j < 1024; ++j) {
			bitset<10>bs(j);
			vector<int>a, b;
			for (int k = 0; k < 10; ++k) {
				if (bs[k])a.emplace_back(nums[k]);
				else b.emplace_back(nums[k]);
			}
			if (is_sorted(a.begin(), a.end()) && is_sorted(b.begin(), b.end()))ok = true;


		}
		if (ok)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}