#include<algorithm>
#include<iostream>
#include<cstring>
#include<climits>
#include<cstdio>
using namespace std;
int T,a[15],isac;
void dfs(int num,int left,int right)
{
    if(num==11){isac=1;return ;}
    if(a[num]>left)dfs(num+1,a[num],right);
    if(a[num]>right)dfs(num+1,left,a[num]);
}
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        isac=0;
        for(int i=1;i<=10;i++)scanf("%d",&a[i]);
        dfs(1,0,0);
        if(isac)printf("YES\n");
        else printf("NO\n");
    }
}