#include<iostream>
using namespace std;
int main(void)
{
    int bo[11],n,B[11],C[11],b1=0,c1=0,A=0,k=0,l=1;
    cin>>n;
    for(int i=0;i<n;i++){
            C[0]=11;k=0;l=1;B[0]=0;b1=0;c1=0;
        for(int j=0;j<10;j++){
            cin>>bo[j];
        }
        for(int j=0;;j++){
                cout<<bo[j]<<" ";
            if(j==0)B[0]=bo[0];
        if(B[l]<bo[j]){
            b1=1;
            B[l]=bo[l];
            l++;
            cout<<"1\n";
        }else if(C[0]==11){
            C[0]=bo[j];
            k++;
            cout<<"2\n";
        }else if(C[k-1]<bo[j]){
            c1=1;
            C[k]=bo[j];
            cout<<"3\n";
        }else{
            B[l+1]=bo[j];
            l++;
            cout<<"4\n";
        }
        if(j==9||(b1==1&&c1==1))break;
    }
    if(b1==1&&c1==1)cout<<"YES\n";
    else cout<<"NO\n";
    for(int j=0;j<10;j++){
        B[j]=0;C[j]=0;
    }

}
}