#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

bool memo[11][11];
int data[10];

bool ans(int p, int b, int c){
  if(memo[b][c]) return false;
  if(p == 10) return true;
  int d = data[p];
  if(b < d && ans(p+1, d, c)) return true;
  if(c < d && ans(p+1, b, d)) return true;
  memo[b][c] = true;
  return false;
}

int main(){
  int n;
  scanf("%d",&n);
  while(n --> 0){
    memset(memo,0,sizeof(memo));
    REP(i,10) scanf("%d",&data[i]);
    puts(ans(0,0,0)?"YES":"NO");
  }
  return 0;
}