#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int N;

int main() {
   cin >> N;
   for (int i = 0; i < N; i++) {
      int a[10];
      for (int j = 0; j < 10; j++) {
         cin >> a[j];
      }

      bool flag = false;
      for (int mask = 0; mask < (1<<10); mask++) {
         vector<int> b, c;
         for (int j = 0; j < 10; j++) {
            if ( (mask >> j) & 1 ) {
               b.push_back(a[j]);
            } else {
               c.push_back(a[j]);
            }
         }
         bool f = true;
         for (int k = 1; k < b.size(); k++) {
            if (b[k-1] > b[k]) f = false;
         }
         for (int k = 1; k < c.size(); k++) {
            if (c[k-1] > c[k]) f = false;
         }
         if (f) {
            flag = true;
         } 
      }

      if (flag) {
         puts("YES");
      } else {
         puts("NO");
      }
   }

   return 0;
}
