#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],b[11] = {0};
    a[0] = ball.back();
    ball.pop_back();
   int ac = 1;
   int bc = 1;
    int t, flg = 0;
    
    while(ball.empty() == false) {

      t = ball.back();
      ball.pop_back();
      // cout << t << 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(ball.empty() == true) cout << "YES" << endl;
    else cout << "NO" << endl;

    ball.clear();

  }

  return 0;

}