#include <bits/stdc++.h>
#define int long long int
#define us unsigned int
#define null 0
#define m_p make_pair
#define f_i first
#define s_e second
#define p_b push_back

using namespace std;


void IOS()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}





int32_t main()
{
    IOS();
int test;
cin>>test;
while(test--)
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    map<char,int> mp;
    bool flag=true;

    for(int i=0;i<n;i++)
    {
        if(mp.find(s[i])==mp.end())
        {
            mp[s[i]]=i;
        }
        else if(i-mp[s[i]]>1)
        {
            flag=false;
            break;
        }
        mp[s[i]]=i;
    }

    if(flag)
    {
        cout<<"YES"<<endl;
    }

    else
    {
        cout<<"NO"<<endl;
    }
}

}


















