#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int ball[10];
		for(int i = 0; i < 10; i++)cin >> ball[i];
		int b = 0,c = 0;
		for(int i = 0; i < 10; i++){
			if(b > ball[i] && c > ball[i]){
				cout << "NO" << endl;
				goto no;
			}else if(b < ball[i] && c > ball[i])b = ball[i];
			else if(b > ball[i] && c < ball[i])c = ball[i];
			else if(b > c)b = ball[i];
			else c = ball[i];
		}
		cout << "YES" << endl;
		no:;
	}
}
