#include<iostream>
#include <algorithm>
using namespace std;

int ball[10];

bool solve(int i, int a, int b){
	if (i == 10) return true;
	bool ans = false;
	if (a < ball[i]) ans = solve(i + i, ball[i], b);
	if (b < ball[i])ans = solve(i + i, a, ball[i]);
	return ans;
}

int main(){
	int n;
	cin >> n;

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

	return 0;
}
//beatmaniaIIDX 23th copula