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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

int a[10];

bool dfs(int n, int l, int r) {
  if (n >= 10) return true;
  if (l < a[n]) if (dfs(n+1, a[n], r)) return true;
  if (r < a[n]) if (dfs(n+1, l, a[n])) return true;
  return false;
};

int main() {
  int N;
  cin >> N;
  rep(i, 0, N) {
    rep(j, 0, 10) {
      cin >> a[j];
    }
    if (dfs(0, -1, -1)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

  return 0;
};

