#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long> 
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll


signed main(){
  int n; cin>>n;
  
  for(int c=0; c<n; c++){
    int a[15];
    for(int j=0; j<10; j++){
      cin>>a[j];
    }
    
    bool ans=false;
    for(int i=0; i<(1<<10); i++){
      vector<int> ve1,ve2;
      for(int j=0; j<10; j++){
        if(i&(1<<j)) ve1.push_back(a[j]);
        else ve2.push_back(a[j]);
      }
      

      bool no=false;
      for(int j=1; j<ve1.size(); j++){
        if(ve1[j]<ve1[j-1]){
          no=true;
          break;
        }
      }
      for(int j=1; j<ve2.size(); j++){
        if(ve2[j]<ve2[j-1]){
          no=true;
          break;
        }
      }
      if(!no){
        ans=true;
        break;
      }
      
    }
    
    if(ans) cout<<"YES"<<en;
    else cout<<"NO"<<en;
  }
}

