#include <iostream>

int nums[10];

bool dfs(int index, int left, int right)
{
  // std::cout << index << std::endl;
  if (index == 10)
  {
    return true;
  }
  // try put at the larger one
  if (left >= right)
  {
    if (left < nums[index])
    {
      return dfs(index + 1, nums[index], right);
    }
    if (right < nums[index])
    {
      return dfs(index + 1, left, nums[index]);
    }
    return false;
  }
  if (right > left)
  {
    if (right < nums[index])
    {
      return dfs(index + 1, left, nums[index]);
    }
    if (left < nums[index])
    {
      return dfs(index + 1, nums[index], right);
    }
    return false;
  }
  return false;
}

int main()
{
  int count = -1;
  std::cin >> count;
  for (int i = 0; i < count; i++)
  {
    for (int j = 0; j < 10; j++)
    {
      std::cin >> nums[j];
    }
    if (dfs(0, -1, -1))
    {
      std::cout << "YES" << std::endl;
    }
    else
    {
      std::cout << "NO" << std::endl;
    }
  }
  return 0;
}
