#include <iostream>
using namespace std;
int ball[10];

bool dfs(int,int,int);

int main(){
	int n;
	cin>>n;
	for (int i = 0; i < n; i++) {
		for (int& j : ball) cin>>j;
		if(dfs(0,0,0))puts("YES");
		else puts("NO");
	}
	return 0;
}

bool dfs(int b,int c,int m){
	if(m == 9)return (b<ball[m] || c<ball[m]) ? true : false;
	bool res = false;
	if(b<ball[m])res = max(res,dfs(ball[m],c,m+1));
	if(c<ball[m])res = max(res,dfs(b,ball[m],m+1));
	return res;
}