#include <iostream>
#include <stack>

using namespace std;


int n;
int A[10];

bool solve(stack<int> v1, stack<int> v2, int index){
    if (index == 10)
        return true;
    if (v1.empty() || A[index] > v1.top())
        v1.push(A[index]);
    else if(v2.empty() || v2.top() < A[index])
        v2.push(A[index]);
    else
        return false;
    return solve(v1,v2, index + 1);
}

int main(){
    cin>>n;
    stack<int> v1,v2;
    while(n--){
        for (int i = 0; i < 10; ++i) {
            cin>>A[i];
        }
        if (solve(v1,v2,0))
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}
