#include <stdio.h>
#include <stack>

using namespace std;

int main(void){
	int n = 0;
	int a[10];
	stack<int> b, c;
	bool r = true;

	scanf("%d", &n);
	for(int i=0;i<n;++i){
		for(int j=0;j<10;++j){
			scanf("%d", a+j);
		}
		b = stack<int>();
		c = stack<int>();
		r = true;

		for(int j=0;j<10;++j){
			if(b.empty()){
				b.push(a[j]);
			}else if(c.empty()){
				c.push(a[j]);
			}else if(b.top() < a[j] && c.top() < a[j]){
				if(b.top() > c.top()){
					b.push(a[j]);
				}else{
					c.push(a[j]);
				}
			}else if(b.top() < a[j]){
				b.push(a[j]);
			}else if(c.top() <a[j]){
				c.push(a[j]);
			}else{
				r = false;
				break;
			}
		}
		puts(r ? "YES": "NO");
	}
	return 0;
}