#include<iostream>
using namespace std;

int data[10];
bool sumilation(int left,int right,int num){
	if(num == 10) return true;
	
	if(left < data[num]){
		if(sumilation(data[num],right,num+1)) return true;
	} 
	if(right < data[num]){
		if(sumilation(left,data[num],num+1)) return true;
	}
	return false;
	
	
}

int main(){
	int times;
	cin >> times;
	for(int i=0;i<times;i++){
		for(int k=0;k<10;k++)
		cin >> data[k];
		if(sumilation(0,0,0) == true){
		cout << "YES" << endl;
		} else {
		cout << "NO" <<endl;
		}
		
		
	}

}