#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
int ball[15];
int leftFront, rightFront;
bool isOK;
void DFS(int depth)
{
    if(depth == 10 || isOK)
    {
        isOK = true;
        return;
    }

    if(ball[depth] > leftFront)
    {
        leftFront = ball[depth];
        DFS(depth + 1);
    }

    if(ball[depth] > rightFront)
    {
        rightFront = ball[depth];
        DFS(depth + 1);
    }

    return;
}
int main(void)
{
	int n;
	scanf("%d", &n);

	while(n--)
    {
        for(int i = 0; i < 10; i++)
            scanf("%d", &ball[i]);

        isOK = false;
        leftFront = 0;
        rightFront = 0;

        DFS(0);

        if(isOK)
            printf("YES\n");
        else
            printf("NO\n");
    }

	return 0;
}

