#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> ball;
vector<int> A;
vector<int> B;
bool flag;

void solve(int i){
	if(flag == true) return;
	if(i == 10){
		for(int i = 1; i < A.size(); ++i){
			if(A[i - 1] > A[i]){
				return;
			}
		}
		for(int i = 1; i < B.size(); ++i){
			if(B[i - 1] > B[i]){
				return;
			}
		}
		flag = true;
	} else {
		A.push_back(ball[i]);
		solve(i + 1);
		A.pop_back();
		
		B.push_back(ball[i]);
		solve(i + 1);
		B.pop_back();
	}
}

int main(){
	int T; scanf("%d", &T);
	while(T--){
		ball.clear();
		for(int i = 0; i < 10; ++i){
			int digit; scanf("%d", &digit);
			ball.push_back(digit);
		}
	
		flag = false;
		solve(0);
		printf(flag ? "YES\n" : "NO\n");
	}
}
