#include <bits/stdc++.h>
 
using namespace std;
 
#define ar array
#define ll long long
 
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
 


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s;
        cin>>s;
        vector<int> count(26, 0);
        count[s[0] - 'A']++;
        int flag = 0;
        for(int i = 1; i < n; i++){
            if(count[s[i] - 'A'] == -1){
                flag = 1;
                break;
            }
            else if(s[i] != s[i-1] ){
                count[s[i-1] - 'A'] = -1;
                count[s[i] - 'A']++;
            }
        }
        if(flag) cout<<"NO\n";
        else cout<<"YES\n";
        
    }
    
}

    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

