#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define ll long long 
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
     
}
void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int arr[26]={0};
    arr[s[0]-'A']++;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
        {
            if(arr[s[i]-'A']>0)
            {
                cout<<"NO"<<endl;
                return ;
            }
        }
        arr[s[i]-'A']++;
    }
    cout<<"YES"<<endl;
    return ;
}
int main()
{
    // #ifndef ONLIE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}