#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
    int N;
    cin >> N;
    for(int index_n=0;index_n<N;index_n++){
        vector<int> V(10);
        rep(i,10) cin >> V[i];
        // left,right,next
        queue<pair<pair<int,int>,int> > Q;
        Q.push(mp(mp(V[0],0),1));
        bool ok = false;
        while(!Q.empty()){
            int left = Q.front().first.first;
            int right = Q.front().first.second;
            int next = Q.front().second;
            Q.pop();

            if(next == 10){
                ok = true;
                break;
            }
            if(V[next] > left){
                Q.push(mp(mp(V[next],right),next+1));
            }
            if(V[next] > right){
                Q.push(mp(mp(left,V[next]),next+1));
            }
        }
        if(ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}