#include<bits/stdc++.h> 
using namespace std;
void solve()
{
    int t, n;
    string s;
    cin>>t;
    while(t--)
    {
        cin>>n>>s;
        bool ans = true;
        map<char,int > x;
        x[s[0]] ++;
        for(int i = 1; i < n-1; i++)
        {
            if(s[i] != s[i+1] and x.find(s[i+1]) != x.end())
            {
                ans = false;
                break;
            }
            x[s[i]]++;

        }
        ans?cout<<"YES\n":cout<<"NO\n";
    }
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
