#include <bits/stdc++.h>
using namespace std;
int n, m;
int vis[30];
int main()
{
    int T;
    cin >> T;
    while(T--){
    memset(vis,0,sizeof vis);
    int n,flag=0;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0; i < n; ){
        char x = s[i];
        if(vis[s[i]-'A']){
            puts("NO");
            flag=1;
            break;
        }
        vis[s[i]-'A'] = 1;
        while(s[i]==x){
            i++;
        }
    }
    if(flag==0)puts("YES");
    continue;
    }
    return 0;
}