//Hananymous To All

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

#define ll long long

#define fl(i,a,b) for(ll i=a;i<b;i++)

#define fst ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TT  int TT;cin>>TT;while(TT--)

#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define sz size
#define ff first
#define ss second
#define srt(v) sort(v.begin(),v.end())
#define dsrt(v) sort(v.rbegin(),v.rend())

void my_ans_is()
{
  ll n;cin>>n;
  string s;cin>>s;
  map<ll,ll>f;
  fl(i,1,n)
  {
    if(s[i]!=s[i-1]) f[s[i-1]]++;
    if(f[s[i]]>0) {cout<<"NO\n";return;}
  }
  cout<<"YES\n";
}

int main() 
{         

  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
        fst;
        TT
  {      
         my_ans_is();
// Note:-Check bounds in arrays, check limit of int (signed integer overflow)
        }
   return 0;
}