#include <bits/stdc++.h>

using namespace std;

bool dfs(queue<int> q, int a, int b)
{
  if (q.empty())
    return true;

  int front = q.front();
  q.pop();

  if (front > a && dfs(q, front, b))
    return true;
  if (front > b && dfs(q, a, front))
    return true;

  return false;
}

int main()
{
  int N;
  cin >> N;

  for (int n = 0; n < N; n++)
  {

    queue<int> q;

    for (int i = 0; i < 10; i++)
    {
      int x;
      cin >> x;
      q.push(x);
    }

    if (dfs(q, 0, 0))
    {
      cout << "YES" << endl;
    }
    else
    {
      cout << "NO" << endl;
    }
  }
}

