#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;


  for(int q=0; q<n;q++) {
    
    vector <int> ball;
    
    ball.resize(10);
    for(int i=0;i<10;i++) cin >> ball[i];
    reverse(ball.begin(),ball.end());
    
    int a[10] = {0},b[11] = {0};
    a[0] = ball.back();
    ball.pop_back();
   int ac = 1;
   int bc = 1;
   int t;

    cout << "t:a:b" << endl;
    while(ball.empty() == false) {

      t = ball.back();
      ball.pop_back();
      // cout << t << endl;
      cout << t <<":"<< a[ac-1]<<":" << b[bc-1]<<endl;
      
      if(t > a[ac-1] && a[ac-1] >= b[bc-1]) {
	a[ac] = t;
	ac++;
      }
      else if(t > b[bc-1]) {
	b[bc] = t;
	bc++;
      } else break;
    }

    //  for(int i=0;i<ac;i++) cout << a[i] << endl;
    
    if(ac+bc == 11) cout << "YES" << endl << endl;
    else cout << "NO" << endl;

    ball.clear();

  }

  return 0;

}