#include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct P
{
	int x, y;
	P(int x,int y):x(x),y(y){}
	P() :P(-1, -1) {}
};

int A[10];
int N;

bool solve()
{
	vector<int> va, vb;
	va.push_back(0), vb.push_back(0);
	rep(i, 0, 10)
	{
		if (va.back() < A[i])
		{
			va.push_back(A[i]);
		}
		else if (vb.back() < A[i])
		{
			vb.push_back(A[i]);
		}
		else
		{
			return false;
		}
	}
	return true;
}

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

	cin >> N;
	rep(i, 0, N)
	{
		rep(j, 0, 10)
		{
			cin >> A[j];
		}
		cout << (solve() ? "YES" : "NO") << endl;
	}

	return 0;
}
