#include <iostream>
using namespace std;

int n;
int A[10];
bool dfs(int a,int b,int i){
	if(i==9) return a<A[i] || b<A[i];
	if(a<=A[i] && !(b<=A[i])) return dfs(A[i],b,i+1);
	else if(b<=A[i]) return dfs(a,A[i],i+1);
	else return false;
}
int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin >> A[j];
		}
		if(dfs(0,0,0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}
