import std.stdio, std.algorithm, std.string, std.conv, std.array;

void main()
{
    foreach(unused; 0 .. readln.chomp.to!int)
    {
        int left = 0, right = -1;
        bool flag = true;
        foreach(n; readln.split.map!(to!int))
        {
            if(n > left && n > right)
            {
                if(left > right) left = n;
                else             right = n;
            }
            else if(n > left) left = n;
            else if(n > right) right = n;
            else
            {
                flag = false;
                break;
            }
        }
        (flag ? "YES" : "NO").writeln;
    }
}