#include <iostream>
using namespace std;

int N;
int ball[10];
bool dfs(int,int,int);

int main(){
    cin>>N;
    while(N--){
        for(int i=0; i<10; i++)
            cin>>ball[i];
        if(dfs(0, 0, 0)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

bool dfs(int left, int right, int n){
    if(n==9 && (ball[9]>left || ball[9]>right)) return true;
    if(ball[n]>left && dfs(ball[n], right, n+1)) return true;
    if(ball[n]>right && dfs(left, ball[n], n+1)) return true;
    return false;
}
