#include<bits/stdc++.h>
#define int long long
using namespace std;

int fx(int n){
  int cnt =0 ;
  while(n > 0){
      n/=10;
      cnt++;
  }

  return cnt;
}

bool check(string s){


  int n = s.length();
  string t = "";

  for(int i =0 ; i < n ; i++){
     if(t.empty()){
      t.push_back(s[i]);
     }else if(t.back() == s[i]){
      continue;
     }else{
      t.push_back(s[i]);
     }
  }

  map<int,int>mp;
  for(auto i : t){
    mp[i]++;
    if(mp[i] > 1)return false;
  }

  return true;

}

signed main(){  

  int t;
  cin >> t;

  while(t--){
      
     int n;
     cin >> n;

     string s;
     cin >> s;

     if(check(s)){
      cout<<"YES\n";
     }else{
      cout<<"NO\n";
     }

  }

  return 0;
}
