#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int n;
int dp[10][10][10] = {0};
int balls[10];

int dfs(int left, int right, int num)
{
	if(num == 10) return 1;
	if(dp[left][right][num]) return dp[left][right][num];
	int ret1 = 0, ret2 = 0;
	if(left <= balls[num]) ret1 = dfs(balls[num], right, num+1);
	if(right <= balls[num] && ret1 != 1) ret2 = dfs(left, balls[num], num+1);
	return dp[left][right][num] = (ret1 == 1 || ret2 == 1 ? 1 : -1);
}

int main(void)
{
	while(cin >> n && n)
	{
		for (int i = 0; i < n; i++)
		{
			memset(dp, 0, sizeof(dp));
			for (int j = 0; j < 10; j++)
			{
				int x; cin >> x; x--;
				balls[j] = x;
			}
			cout << (dfs(0,0,0) == 1?"YES":"NO")<< endl;
		}
	}
	return 0;
}