#include<stdio.h>
#include<string.h>
int main()
{
    int t,n,in =0;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        char a[n];
        scanf("%s",&a);
        in =0;
        for(int i=0;i<n;i++)
        {
           for(int j =i+1;j<n;j++)
           {
               if(a[i]!=a[j])
               {
                   for(int c=j+1;c<n;c++)
                   {
                       if(a[i]==a[c])
                       {
                           in =1;
                           printf("NO\n");
                           break;
                       }
                   }
               }
               if(in == 1) break;
           }
          if(in == 1) break;
        }
        if(in ==0)printf("YES\n");
    }
    return 0;
}
