#include <stack>
#include <cstdio>
using namespace std;
  int main(){
    int a,b,n,i,j,x[10];
    scanf("%d",&n);
for(j=0;j<n;j++){
    for(i=0;i<10;i++){
       scanf("%d",&x[i]);
}
stack<int> B;
stack<int> C;
B.push(x[0]);
for(i=1;i<=9;i++){
if(x[i-1]>x[i]){
C.push(x[i]);
goto ccc;
}else{
	B.push(x[i]);
	goto bbb;
}
bbb:;
}
ccc:
for(j=i;j<9;j++){
if(B.top()<x[j+1]){
B.push(x[j+1]);
}else if(C.top()<x[j+1]){
	C.push(x[j+1]);
}else{
	printf("NO\n");
	goto aaa;
}
}
printf("YES\n");
aaa:;
}
return 0;
  }