#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	cin >> n;
	while(n--){
		int d[10];
		int dp[10]={1,1,1,1,1,1,1,1,1,1},m[10]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
		rep(i,10) cin >> d[i];
		rep(i,10) rep(j,i) if(d[j] < d[i]) if(dp[i] <= dp[j]){ dp[i] = dp[j]+1 , m[i] = j;}
		int p = find( dp , dp+10 , *max_element( dp , dp+10 ) ) - dp;
		while(~p){ d[p] = -1; p = m[p];}
		bool ans = true; int prev = -1;
		rep(i,10) if(~d[i]){
			if(d[i] > prev) prev = d[i];
			else ans = false;
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
}