#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;


int main(void){

int N, tm[10];
	cin >> N;
	rep(qq,N){
		bool chk = true;
		int bh=0,ch=0;
		rep(i,10) cin >> tm[i];
		rep(i,10){
			if(bh > tm[i] && ch > tm[i]){
				chk = false;
//				printf("i=%i (%d,%d)\n",i,bh,ch);
				break;
			}
			if(bh > tm[i] && ch < tm[i]) ch =tm[i];
			else if(ch > tm[i] && bh < tm[i]) bh =tm[i];
			else if(tm[i] -bh < tm[i] -ch) bh = tm[i];
			else                    ch = tm[i];
		}
		cout << (chk ? "YES": "NO") << endl;
	}
	return 0;
	
	
}