#include <iostream>
#include <cstring>

using namespace std;

string s;
int n, T;
int a[26];
bool f[26];

int main(){
    cin >> T;
    while(T--){
        int flag = 1;
        cin >> n >> s;
        memset(a, 0, sizeof(a));
        for (int i = 0; i < 26; i++) f[i] = true;
        a[s[0] - 'A']++;
        f[s[0] - 'A'] = false;
        for (int i = 1; i < s.size(); i++){
            if(s[i]==s[i-1]) continue;
            else if(f[s[i] - 'A']){
                f[s[i] - 'A'] = false;
                a[s[i] - 'A']++;
            }
            else{
                flag = 0;
                cout << "NO" << endl;
                break;
            }
        }
        if(flag) cout << "YES" << endl;
    }
    return 0;
}