#include <iostream>

using namespace std;

int ball[10];
bool dfs(int n,int l,int r){
	if(n == 10)
		return true;
	if(ball[n]>l&&dfs(n+1,ball[n],r))
		return true;
	if(ball[n]>r&&dfs(n+1,l,ball[n]))
		return true;
	return false;
}


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