#include<stdio.h>
#include<bits/stdc++.h>

typedef long long ll;

using namespace std;


int main()
{
    ll deva;
    cin>>deva;
    for(ll ol=0;ol<deva;ol++)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        int a[26]={0};
        int flag=1;
        a[s[0]-'A']+=1;
        for(int i=1;i<n;i++)
        {
            if(a[s[i]-'A']>0 && s[i]!=s[i-1])
            {
                flag=0;
                break;
            }
            a[s[i]-'A']+=1;
        }
        if(flag)
            cout<<"YES"<<endl;
        else    
            cout<<"NO"<<endl;
    }
    return 0;
}