#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;
int cas_e;
int b[10],l[10]={0},r[10]={0};
void dfs(int x,int y,int z)
{
    if(x==10){cas_e=1;return;}
    if(cas_e){return;}
    if(b[x]>l[y]){l[y]=b[x];dfs(x+1,y+1,z);}
    if(b[x]>r[z]){r[z]=b[x];dfs(x+1,y,z+1);}
}
int main()
{
    int a;
    cin>>a;
    while(a--)
    {
        for(int i=0;i<10;i++)
        {
            cin>>b[i];
        }
        cas_e=0;
        dfs(0,0,0);
        if(cas_e){cout<<"YES"<<endl;}
        else{cout<<"NO"<<endl;}
    }
    return 0;
}


