#include <iostream>

using namespace std;

int main()
{
    int n; cin>>n;
    while(n--){
        int amin = 0;
        int bmin = 0;
        int tmp;
        bool ans = true;
        for(int i=0;i<10;++i){
            cin>>tmp;
            if(tmp <= amin && tmp <= bmin){
                ans = false;
            }
            if(!ans) continue;
            if(tmp > amin && tmp > bmin){
                if(bmin > amin)
                    bmin = tmp;
                else
                    amin = tmp;
            }else if(tmp > amin)
                amin = tmp;
            else
                bmin = tmp;
        }
        if(ans) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

