#include <iostream>
#include <algorithm>

using namespace std;

int n;
int stock[2][11];
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num] > stock[0][r_num]) {
		if (num == 9)
			return 1;
		stock[0][r_num + 1] = num;
		res = dfs(num + 1, r_num + 1, l_num);
		stock[0][r_num + 1] = -1;
		return res;
	}
	else if (usea[num] > stock[1][l_num]) {
		if (num == 9)
			return 1;
		stock[1][l_num + 1] = num;
		res = dfs(num + 1, r_num, l_num + 1);
		stock[1][l_num + 1] = -1;
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> usea[j];
		}
		if (dfs(0, 0, 0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

	return 0;
}