#include <iostream>

using namespace std;

int N;
int a[10];

bool dfs(int left, int right, int next)
{
	if(next >= 10) return true;
	
	bool ret1 = false, ret2 = false;
	if(left < a[next]) ret1 = dfs(a[next], right, next+1);
	if(right < a[next]) ret2 = dfs(left, a[next], next+1);
	
	return ret1 || ret2;
}

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++){
		
		for(int j = 0; j < 10; j++) cin >> a[j];
		bool ans = dfs(0, 0, 0);
		
		if(ans) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}