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

void main()
{
    foreach(unused; 0 .. readln.chomp.to!int)
    {
        int[11] dp, path, input;
        path[0] = -1;
        input[0] = dp[0] = 0;
        input[1 .. 11] = readln.split.map!(to!int).array[0 .. 10];

        int tail;
        foreach(i; 1 .. 11)
        {
            int max = int.min, maxIndex;

            foreach(j; 0 .. i)
            {
                if(input[i] > input[j] && max < dp[j])
                {
                    max = dp[j];
                    maxIndex = j;
                }
            }

            dp[i] = max + 1;
            path[i] = maxIndex;

            if(dp[tail] < max)
            {
                tail = i;
            }
        }

        for(int i = tail; i != 0; i = path[i])
        {
            input[i] = -1;
        }

        int prev = int.min;
        bool flag = true;
        foreach(i; 1 .. 11)
        {
            if(input[i] == -1) continue;
            if(prev > input[i])
            {
                flag = false;
                break;
            }
            else
            {
                prev = input[i];
            }
        }
        (flag ? "YES" : "NO").writeln;
    }
}