a[10];int dfs(int l,int r,int i){if(i>9)return 1;if(a[i]>l&&dfs(a[i],r,i+1))return 1;if(a[i]>r&&dfs(l,a[i],i+1))return 1;return 0;
}main(n){scanf("%d",&n);for(;n;n--)scanf("%d%d%d%d%d%d%d%d%d%d",a+0,a+1,a+2,a+3,a+4,a+5,a+6,a+7,a+8,a+9),dfs(0,0,0)?puts("YES"):puts("NO");return 0;}