#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a[26]={0};
        int n,f=0;
        cin>>n;
        string s;
        cin>>s;
        for(int i=1;i<n;i++)
        {
            if(a[s[i]-65]==1)
              {
                  f=1;
                  break;
              }
            if(s[i]!=s[i-1])
              {
                  a[s[i-1]-65]=1;
              }
        }
        if(f==1)
         cout<<"NO"<<endl;
        else
         cout<<"YES"<<endl;
    }
   
    return 0;
}
