#include<iostream>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<math.h>
#include<string>
#include<stack>
#include<typeinfo>
using namespace std;
typedef pair<int, int> P;
int main() {
	int n,ball[10],under;
	cin >> n;
	for (int data = 0; data < n; ++data) {
		for (int i = 0; i < 10; ++i) cin >> ball[i];
		under = ball[0];
		ball[0] = 0;
		for (int i = 1; i < 10; ++i) {
			if (under < ball[i]) {
				under = ball[i];
				ball[i] = 0;
			}
		}
		int k;
		for (k = 1; k < 10; ++k) {
			if (ball[k] == 0)continue;
			else {
				under = ball[k];
				ball[k] = 0;
				break;
			}
		}
		char bo = true;
		for (int i = k + 1; i < 10; ++i) {
			if (ball[i] == 0)continue;
			else if (under < ball[i]) {
				under = ball[i];
				ball[i] = 0;
			}
			else {
				bo = false;
				break;
			}
		}
		if (bo)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}
