#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
#define FOR(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;

int main(void){
	queue <int> rque, lque;
	int N;
	cin >> N;
	for(int k = 0; k < N; k++){
		int have[10];
		for(int j = 0; j < 10; j++){
			cin >> have[j];
		}
		int set = have[9];
		have[9] = -1;
		for(int i = 8; i >= 0; i--){
			if(set > have[i]){
				set = have[i];
				have[i] = -1;
			}
		}
		for(int i = 8; i >= 0; i--){
			if(have[i] != -1){
				set = have[i];
				have[i] = -1;
				break;
			}
		}
		for(int i = 8; i >= 0; i--){
			if(have[i] != -1 && set > have[i]){
				set = have[i];
				have[i] = -1;
			}
		}
		for(int i = 0; i < 10; i++){
			if(have[i] != -1){
				cout << "NO" << endl;
				break;
			}else{
				cout << "YES" << endl;
				break;
			}
		}

	}

	return 0;	
}