
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>
#include <set>
#include <numeric>

using namespace std;

double sq(double x){return x*x;}

int main(){
	int t;
	cin>>t;
	while(t--){
		int a[10];
		bool t[10];
		for (int i = 0; i < 10; i++)
		{
			cin>>a[i];
		}
		memset(t,0,10);
		int b;
		for (int i = 0; i < 2; i++)
		{
			b = 0;
			for (int j = 0; j < 10; j++)
			{
				if(t[j])continue;
				if(b < a[j]){
					b = a[j];
					t[j] = true;
				}
			}
		}
		int s = accumulate(t,t+10,0);
		if(s == 10)
			puts("YES");
		else 
			puts("NO");
	}

	return 0;
}