#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int a,b,temp,n;
int main()
{
    int n;
    cin>>n;
    while(n--){
        queue<int>que;
        for(int i=0;i<10;i++){
            cin>>temp;
            que.push(temp);
        }
        while(que.size()){
            temp=que.front();
            que.pop();
            if(temp<=a&&temp<=b){
                cout<<"NO\n";
                return 0;
            }
            else if(temp<=a&&temp>b)b=temp;
            else if(temp<=b&&temp>a)a=temp;
            else {
                if(a>=b)a=temp;
                else b=temp;
            }
        }
        cout<<"YES\n";
    }

    return 0;
}