#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n][10];
    vector<int> b,c;
    rep(i,n)rep(j,10){
        cin >> a[i][j];
    }
    b.pb(0);
    c.pb(0);
    rep(i,n){
        bool flag = true;
        rep(j,10){
            int p1 = b[b.size()-1];
            int p2 = c[c.size()-1];
            int p = a[i][j];
            if(p < p1 && p < p2){
                cout << "NO" << endl;
                flag = false;
                break;
            }else if(p < p1 && p > p2){
                c.pb(p);
            }else if(p > p1 && p < p2){
                b.pb(p);
            }else{
                if(p1 < p2){
                    c.pb(p);
                }else{
                    b.pb(p);
                }
            }
        }
        if(flag){
            cout << "YES" << endl;
        }
        b.clear();
        c.clear();
        b.pb(0);
        c.pb(0);
    }
}
