#include <iostream>
#include <climits>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <vector>

#define ll long long
#define REP(i, n) for (int i=0;i<n;++i)
#define REP_1(i, n) for (int i=1;i<=n;++i)
#define REP_2(i, j, n, m) REP(i, n) REP(j, m)
#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)

#define JU_RAN(a,x,b) a<=x&&x<=b



using namespace std;

int v[15];
void solve(){
    int n;
    cin>>n;
    while (n--){
        REP_1(i,10)cin>>v[i];
        stack<int > a;
        stack<int > b;
        a.push(0);
        b.push(0);

        bool f=1;
        REP_1(i,10){
            if(a.top()>=b.top()){
                if(a.top()<v[i]){
                    a.push(v[i]);
                } else if(b.top()<v[i]){
                    b.push(v[i]);
                } else{
                    f=0;
                    break;
                }
            }
            else{
                if(b.top()<v[i]){
                    b.push(v[i]);
                } else if(a.top()<v[i]){
                    a.push(v[i]);
                } else{
                    f=0;
                    break;
                }
            }
        }

        if(f){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

    }

}



int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    solve();



#ifdef LOCAL_DEFINE
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
