#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;


ll n, a[100];
stack<int> vi1, vi2;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> a[j];
		}
		REP(j, 10){
			if (vi1.empty()){
				vi1.push(a[j]);
				continue;
			}
			if (vi2.empty()){
				if (vi1.top() > a[j]){
					vi2.push(vi1.top());
					vi1.pop();
					vi1.push(a[j]);
				}
				else{
					vi2.push(a[j]);
				}
				continue;
			}
			if (vi2.top() < a[j]){
				vi2.push(a[j]);
			}
			else{
				if (vi1.top() < a[j]){
					vi1.push(a[j]);
				}
				else{
					cout << "NO" << endl;
					break;
				}
			}
			if (j == 10 - 1){
				cout << "YES" << endl;
			}
		}
		while (!vi1.empty()){
			vi1.pop();
		}
		while (!vi2.empty()){
			vi2.pop();
		}
	}
}