#include<bits/stdc++.h>
#include <vector>
using namespace std;


#define f(i,n)          for(int i=0;i<n;i++)
#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x  //works with float
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(x)          x.begin(),x.end()
#define rt              return
#define br              break
#define ct              continue
#define elif            else if
#define arrin(a,n)      for(int i=0;i<n;i++)cin>>a[i]
#define arrout(a,n)     for(int i=0;i<n;i++)cout<<a[i]<<" "
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

int log_a_to_base_b(int a, int b)
{
    return log(a) / log(b);
}

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
}

string subsequence(string s, int binary, int len)
{
    string sub = "";
    for (int j = 0; j < len; j++)

        // check if jth bit in binary is 1
        if (binary & (1 << j))

            // if jth bit is 1, include it
            // in subsequence
            sub += s[j];

    return sub;
}

// function to print all subsequences
vector<string> possibleSubsequences(string s) {

    vector<string> vs;

    // map to store subsequence
    // lexicographically by length
    map<int, set<string> > sorted_subsequence;

    int len = s.size();

    // Total number of non-empty subsequence
    // in string is 2^len-1
    int limit = pow(2, len);

    // i=0, corresponds to empty subsequence
    for (int i = 1; i <= limit - 1; i++) {

        // subsequence for binary pattern i
        string sub = subsequence(s, i, len);

        // storing sub in map
        sorted_subsequence[sub.length()].insert(sub);
    }

    for (auto it : sorted_subsequence) {

        // it.first is length of Subsequence
        // it.second is set<string>
        cout << "Subsequences of length = "
             << it.first << " are:" << endl;

        for (auto ii : it.second) {

            // ii is iterator of type set<string>
            cout << ii << " ";
            vs.pb(ii);
        }

        cout << endl;
    }
    return vs;
}


string DecimalToBinaryString(int a)
{
    string binary = "";
    int mask = 1;
    for (int i = 0; i < 31; i++)
    {
        if ((mask & a) >= 1)
            binary = "1" + binary;
        else
            binary = "0" + binary;
        mask <<= 1;
    }
    // cout<<binary<<endl;
    return binary;
}



int32_t main()
{


    w(t) {
        int l;
        cin >> l;
        string s;
        cin >> s;
        string s2 = s;
        int a[26] = {0};
        bool b1 = false;

        f(i, l) {
            int d = s.at(i);
            d -= 65;
            if (a[d] == 0) {
                a[d] = 1;
            }
            else if (a[d] == 1 and s.at(i) == s.at(i - 1) and i != 0) {
                continue;
            }
            else {
                b1 = true;
            }

        }

        if (b1) {
            cout << "NO" << endl;
        }
        else
            cout << "YES" << endl;
        // sort(s2.begin(), s.end());
        // reverse(s2.begin(), s2.end());

        // bool b1 = false, b2 = false;

        // if (is_sorted(s.begin(), s.end())) {
        //     b1 = true;
        // }
        // if (s2 == s) {
        //     b2 = true;
        // }
        // if (b2 or b1) {
        //     cout << "YES" << endl;
        // }
        // else
        //     cout << "NO" << endl;





    }






}
















