#include <stdio.h>
#include <stdlib.h>
int main() {
int n;
int list[10];
int a, b;
scanf(" %d", &n);
for (int register i = 0; i < n; i++) {
for (int register j = 0; j < 10; j++) {
scanf(" %d", &list[j]);
}
a = 0;
b = 0;
int success = 1;
for (int register j = 0; j < 10; j++) {
if (a < list[j]) {
if (b < list[j]) {
if (a < b) b = list[j];
else a = list[j];
} else {
a = list[j];
}
} else {
if (b < list[j]) {
b = list[j];
} else {
success = 0;
break;
}
}
}
if (success) {
printf("YES\n");
} else {
printf("NO\n");
}
}
}