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

bool check(vector<int>& s){
	int crt = 0;
	bool res = true;
	for(int i = 0;i < s.size();++i){
		if(s[i] > crt) crt = s[i];
		else{
			res = false;
			break;
		}
	}
	return res;
}

int main(){
	int n;cin >> n;
	cin.get();
	while(n--){
		vector<int> nums(10);
		for(int i = 0;i < 10;++i) cin >> nums[i];
		int size = 10;
		bool res = false;
		for(int i = 0;i < (1<<size);++i){
			vector<int> num1,num2;
			for(int j = 0;j < size;++j){
				if((i>>j)&1) num1.push_back(nums[j]);
				else num2.push_back(nums[j]);
			}
			if(check(num1) && check(num2)){
				res = true;
				break;
			}
		}
		if(res) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}
