#include<bits/stdc++.h>
#define optimize() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define testCase int testcase; cin >> testcase; while(testcase--)
#define ll long long int
#define endl "\n"
#define mod (int)(1e9 + 7)
using namespace std;
int main()
{
    testCase
    {
        int n;
        cin >> n;
        string s;
        cin >> s;
        
        bool ok = true;
        vector <char> v;
        v.push_back(s[0]);
        for(int i=1; i<n; i++)
        {
            if(s[i]!=s[i-1])
            {
                v.push_back(s[i]);
            }
        }
        /* if(s[n-1] != s[n-2] && s[n-2]!=s[n-3] && n>2){
            v.push_back(s[n-1]);
        } */
        
        sort(v.begin(), v.end());
        for(int i=0; i<v.size()-1; i++){
            if(v[i]==v[i+1]){
                ok = false;
            }
        }
        //for(auto it : v)cout << it; cout << endl;
        if(!ok)
            cout << "NO" << endl;
        else
            cout << "YES" << endl;
    }
    return 0;
}
