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

int times[28];

void solve(void){
    memset(times,0,sizeof(times));
    string s;
    int t = 1;
    cin >> t >> s;
    for(int i = 0;i < s.length();i++){
        if(times[s[i] - 'A']){
            cout << "NO\n";
            return;
        }
        times[s[i] - 'A']++;
        t = 1;
        while(s[i + t] == s[i]) t++;
        i += t - 1;
    }
    cout << "YES\n";
}

int main(void){
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}