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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    int a[10];
    REP(j, 10) cin >> a[j];
    bool ok = false;
    for (int mask = 0; mask < 1 << 10; ++mask) {
      int max1 = 0, max2 = 0;
      bool ok2 = true;
      REP(j, 10) {
        if (mask >> j & 1) {
          if (max1 < a[j])
            max1 = a[j];
          else
            ok2 = false;
        } else {
          if (max2 < a[j])
            max2 = a[j];
          else
            ok2 = false;
        }
      }
      if (ok2) {
        ok = true;
        break;
      }
    }
    cout << (ok ? "YES" : "NO") << endl;
  }
  return 0;
}
