//0033
//include-------------------------------------
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<stack>

using namespace std;

//typedef--------------------------------------
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define MP make_pair

//repetition-----------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

//constant-------------------------------------
const double PI = acos(-1.0);

//cout,cin-------------------------------------
#define COUT(x) cout<<(x)<<endl;
#define CIN(x) cin>>(x);


int main(){
	int n;
	int x[10];
	bool ans;

	CIN(n);

	REP(i, n){
		
		REP(j, 10) CIN(x[j]);
		stack<int> B, C;
		B.push(0);
		C.push(0);

		REP(j, 10){
			if ((B.top() > x[j]) && (C.top() > x[j])){
				ans = false;
				break;
			}
			else { 
				if ((B.top() >= C.top()) && (B.top() < x[j])) B.push(x[j]);
				else C.push(x[j]);
			}

		}
		COUT(ans==false?"NO":"YES");
		
	}