#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

bool dfs(vector<int>::iterator iter, vector<int>::iterator end, int left, int right) {
  if(iter == end) return true;
  bool res = false;
  if(*iter > left) res |= dfs(iter + 1, end, *iter, right);
  if(*iter > right) res |= dfs(iter + 1, end, left, *iter);
  return res;
}

bool solve() {
  vector<int> a(10);
  for(int i = 0;i < 10;i++) cin >> a[i];
  return dfs(begin(a), end(a), 0, 0);
}

int main() {
  int t;
  cin >> t;
  for(int i = 0;i < t;i++) {
    if(solve()) {
      cout << "YES" << endl;
    }
    else {
      cout << "NO" << endl;
    }
  }
}

