using System;
class _0033
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            string[] data = Console.ReadLine().Split();
            Console.WriteLine(Judge(data) ? "YES" : "NO");
        }
    }
    public static bool Judge(string[] data)
    {
        int right = 0;
        int left = 0;
        for (int i = 0; i < data.Length; i++)
        {
            if (right < int.Parse(data[i])) right = int.Parse(data[i]);
            else if (left < int.Parse(data[i])) left = int.Parse(data[i]);
            else return false;
        }
        return true;
    }
}