#include <iostream>
using namespace std;
int a[10];
bool dfs(int i,int j,int k){
	return(k==10||(i<a[k]&&dfs(a[k],j,k+1))||(j<a[k]&&dfs(i,a[k],k+1)));
}
int main() {
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++)cin>>a[j];
		cout<<(dfs(0,0,0)?"YES":"NO")<<endl;
	}
}