#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include "stdio.h"
#include <string>
int si[10];
bool stack(int left, int right, int i){
	if (i == 9){
		if (left < si[i] || right < si[i]){
			return true;
		}
		else return false;
	}
	else if (left <= si[i]){
		return stack(si[i], right, i + 1);
	}
	else if (right <= si[i]){
		return stack(left, si[i], i + 1);
	}
	else return false;
}
int main(){
	int n;
	std::cin >> n;
	for (int e = 0; e<n; e++){
		for (int ai = 0; ai<10; ai++){
			std::cin >> si[ai];
		}
		if (stack(0, 0, 0) == true){
			std::cout << "YES\n";
		}
		else {
			std::cout << "NO\n";
		}
	}
}