#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int b = 0, c = 0;
		int flag = 1;
		for (int j = 0; j < 10; j++){
			int k;
			cin >> k;
			if (b < k && c < k) {
				if (b > c) {
					b = k;
				} else {
					c = k;
				}
			} else if (b < k && c >= k) {
				b = k;
			} else if (b >= k && c < k) {
				c = k;
			} else{
				flag = 0;
				break;
			}
		}
		if (flag) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}