#include <bits/stdc++.h>
#define ll long long
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int n,i,f,l,j;
string w;
bool check()
{
    for(j=f;j<=l;j++)
    {
        if(w[j]==w[i])
            continue;
        else
            return false;
    }
    return true;
}
void solve()
{
    cin>>n;
    cin>>w;
    for(i=0;i<n;i++)
    {
        f=w.find_first_of(w[i]);
        l=w.find_last_of(w[i]);
        if(!check())
        {
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }

}
