#include<bits/stdc++.h>
using namespace std;
#define foi(i,n) for(int i = 0 ; i < n ; i++)

#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define M 1000000007
int main(){
int t;
cin >> t;
     abc:   while(t--){
          int n ;
          cin >> n ;
          string str;
          cin >> str;
          int a[26] = {0};
          for(int i = 0 ; i < n ; i++){
            if(a[str[i]-'A']==0){
                a[str[i] - 'A']++;
            }
            else if(str[i] == str[i-1]) continue;
            else {
                cout << "NO\n"; goto abc;
            }
          }
          cout << "YES\n";

        }


   return 0;
}
