#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
typedef vector<edge> edges;
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int a[10];
bool ans;
void solve(int i, int l, int r)
{
	if (i == 10) ans = true;
	if (l < a[i]) return solve(i + 1, a[i], r);
	if (r < a[i]) return solve(i + 1, l, a[i]);
}

int main()
{
	int n;
	cin >> n;
	REP(x, n)
	{
		ans = false;
		REP(i, 10) cin >> a[i];
		solve(0, 0, 0);
		cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}