#include<iostream>
using namespace std;
#define N 10
int flag;
int shunxu[N+5];
void dfs(int x1,int y1,int x2,int y2,int ans) {
	if (x2 < x1 || y2 < y1)
		return;
	if (ans == 10) {
		flag = 1;
		return;
	}
	dfs(x2, y1, shunxu[ans], y2, ans + 1);
	dfs(x1, y2, x2, shunxu[ans], ans + 1);
}
int main()
{
	int n;
	cin >> n;
	while (n--) {
		for (int i = 0; i < N; i++) {
			cin >> shunxu[i];
		}
		flag = 0;
		dfs(0, 0, 0, 0, 0);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}
