#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  for (int a = 0; a < N; ++a) {
    vector<int> A(10);
    for (int i = 0; i < 10; ++i)
      cin >> A[i];

    bool flag = false;
    for (int bit = 0; bit < 1 << 10; ++bit) {
      vector<int> B1(10), B2(10);
      int B1_size = 0, B2_size = 0;
      for (int i = 0; i < 10; ++i)
        if (bit & 1 << i)
          B1[B1_size] = A[i], ++B1_size;
        else
          B2[B2_size] = A[i], ++B2_size;

      vector<int> B1_s = B1, B2_s = B2;
      sort(B1_s.begin(), B1_s.begin() + B1_size),
          sort(B2_s.begin(), B2_s.begin() + B2_size);

      if (B1 == B1_s && B2 == B2_s)
        flag = true;
    }

    if (flag)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
