#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  for (int _ = 0; _ < n; ++_) {
    V<> a(10); for (int i = 0; i < 10; ++i) cin >> a[i];
    bool ok = false;
    for (int bit = 0; bit < 1 << 10; ++bit) {
      V<> b, c;
      for (int i = 0; i < 10; ++i) if (bit & 1 << i) {
        b.push_back(a[i]);
      } else {
        c.push_back(a[i]);
      }
      if (is_sorted(begin(b), end(b)) and is_sorted(begin(c), end(c))) {
        ok = true;
        break;
      }
    }
    cout << (ok ? "YES" : "NO") << '\n';
  }
}
