#include<iostream>
#include<map>
#include<cstring>
#include<cmath>
#include<algorithm>
#include <queue>
#include<map>
using namespace std;
typedef long long ll;
inline ll gcd(ll a,ll b) {
    return b>0 ? gcd(b,a%b):a;
}
int main()
{
	ll T,m1,m,k,a,b;
	cin>>T;
	while(T--){
		int a[30]={0},n;
		cin>>n;
		string str;
		cin>>str;
		int num=-1,f=1;
		for(int i=0;i<str.length();i++){
			int tmp=str[i]-'A';
			if(tmp!=num)
			{
				if(a[tmp])
				f=0;
				else
				{
					num=tmp;
					a[tmp]++;
				} 
			}
		}
		if(f)
		cout<<"YES\n";
		else
		cout<<"NO\n";
	}
	}

