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

int main() {
  int n; cin >> n;
  while (n--) {
    vector<int> a(10); for (int i = 0; i < 10; ++i) cin >> a[i];
    int sum = 0;
    for (int i = 1; i < 10; ++i) {
      sum += (a[i - 1] > a[i]);
    }
    cout << ( (sum < 3) ? "YES" : "NO" ) << endl;
  }
  return 0;
}

