#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#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()

int main() {
  int n;
  cin >> n;
  while(n--) {
    int a[10];
    REP(i,10) {
      cin >> a[i];
    }
    int i;
    for (i=0; i<(1<<10); i++) {
      int s=0,t=0;
      int j;
      for (j=0; j<10; j++) {
        if (1&(i>>j)) {
          if (a[j]>s)
            s=a[j];
          else
            break;
        } else {
          if (a[j]>t)
            t=a[j];
          else
            break;
        }
      }
      if (j==10) break;
    }
    if (i!=(1<<10))
      cout << "YES" << endl;
    else
      cout <<"NO" <<endl;
  }
}