#include <stdio.h>
int RideBack[10];
bool check(int val) {int B=-1,C=-1,q;for (q=9;q>=0;q--,val>>=1) if (val&1) {if (B<RideBack[q]) B=RideBack[q]; else break;} else {if (C<RideBack[q]) C=RideBack[q]; else break;} return (q<0);}
int main() {int N,i;scanf("%d",&N);while (N--) {for (i=9;i>=0;scanf("%d",&RideBack[i--]));for (i=0;i<1024;i++) if (check(i)) break;if (i==1024) puts("NO"); else puts("YES");}return 0;}