#include <iostream>
#include <algorithm>

using namespace std;

int main(void){

  int b[5];
  int c[5];

  int n;
  cin >> n;
  while(n--){

    int a[10];
    int j = 0;
    int k = 0;
    for( int i = 0 ; i < 10 ; i++ ){
      cin >> a[i];
      if( i % 2 == 0 ){
	b[j++] = a[i];
      }
      if( i % 2 == 1 ){
	c[k++] = a[i];
      }
    }
    int temp_b[5];
    int temp_c[5];

    for( int i = 0 ; i < 5 ; i++ ){
      temp_b[i] = b[i];
      temp_c[i] = c[i];
    }

    sort( b , b + 5 );
    sort( c , c + 5 );

    int cnt_b = 0;
    int cnt_c = 0;

    for( int i = 0 ; i < 5 ; i++ ){
      if( temp_b[i] == b[i] )cnt_b++;
      if( temp_c[i] == c[i] )cnt_c++;
    }
    if( cnt_b == 5 && cnt_c == 5 ) cout << "YES" << endl;
    else cout << "NO" << endl; 
  }
  return 0;
}