#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const int mod = 1e9+7;
const int N = 1e6+10;

#pragma region Debugger
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion Debugger
 
//My tools
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,s,e)  for(int i=s;i<e;i++)
#define all(v)  (v).begin(),(v).end()

void solve(){
    int n;cin>>n;
    int vis[26] = {0};
    string s;cin>>s;
    char prev = s[0];
    vis[s[0]-'A'] = 1;
    for(int i=1;i<n;i++){
        if(s[i]!=prev){
            if(vis[s[i]-'A']){
                cout<<"NO\n";
                return;
            }
            else{
                prev = s[i];
                vis[s[i]-'A'] = 1;
            }
        }

        else continue;
    }
    cout<<"YES\n";
}


signed main(){
    fastio;
    int t=1;
    cin>>t;
    rep(i,1,t+1){
	    solve();
    }
    return 0;
}
