#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    bool flag;
    int num;
    int a,b,t;
    cin >> t;
    while(t--)
    {
        b = 0;
        flag = true;
        for(int i = 0; i < 10; i++)
        {
            scanf("%d",&num);
            if(i == 0)
            {
                a = num;
                continue;
            }
            if(num < a)
            {
                if(num > b)
                {
                    b = num;
                    continue;
                }
                else
                {
                    flag = false;
                    break;
                }
            }
            else if(num > a)
            {
                if(num-a > num-b)
                {
                    b = num;
                    continue;
                }
                else
                {
                    a = num;
                    continue;
                }
            }
        }
        if(flag == true)
        {
            printf("YES\n");
        }
        else printf("NO\n");
        fflush(stdin);
    }
    return 0;
}
