#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll t,n;
int main()  
{  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>t;
    while(t--)
    {
        cin>>n;
        string s;
        cin>>s;
        unordered_map<char,int>mp;
        bool pass=true;
        string temp="";
        temp+=s[0];
        for(int i=1;i<n;i++)
        {
            if(s[i]!=s[i-1] )
            {
                temp+=s[i];
            }
        }
        for(char x:temp)
        {
            mp[x]++;
            if(mp[x]>1)
            {
                pass=false;
                break;
            }
        }
        if(pass)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
    return 0;
}