#include <stdio.h>

int main(void)
{
	int i, j;
	int ball[10];
	int a, b;
	int n;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		for (j = 0; j < 10; j++){
			scanf("%d", &ball[i]);
		}
		
		for (j = 0; j < 10; j++){
			if (ball[i] < a && ball [i] < b){
				printf("NO\n");
				break;
			}
			if (a > b && a < ball[i]){
				a = ball[i];
			}
			else if (a < b && b < ball[i]){
				b = ball[i];
			}
			else if (a < ball[i]){
				a = ball[i];
			}
			else if (b < ball[i]){
				b = ball[i];
			}
		}
		if (j == 10){
			printf("YES\n");
		}
	}
	return (0);
}