#include <bits/stdc++.h>
#include<iostream>
using namespace std;

int main(){
    int t;
    
    cin>>t;
    while(t--){
    
        int n;
        cin>>n;
        string s;
        cin>>s;
        int a=0;
        int vis[27];

 for(int i=0;i<27;i++){
     vis[i]=0;
 }

        for(int i=0;i<n;i++){
            if(vis[s[i]-'A']==0){
            vis[s[i]-'A']++;
            }

            else if (vis[s[i]-'A']!=0 && (s[i]!=s[i-1]))
            {
                a++;
                break;
            }
            
        }
        if(a>0){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
        }
        

    }
}