#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

int main(){
	int t,data[10],A,B;
	scanf("%d",&t);
	while(t--){
		rep(i,10)scanf("%d",data+i);
		A = B = 0;
		int j;
		bool f = true;
		for(j=0; j<10; j++){
			if( A<data[j] && B<data[j] ){
				if( A<B ){
					B = data[j];
				}else{
					A = data[j];
				}
			}else if( A<data[j] ){
				A = data[j];
			}else if( B<data[j] ){
				B = data[j];
			}else{
				f = false; break;
			}
		}
		puts(f ? "YES" : "NO" );
	}
	return 0;
}