#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5; 
char  s[maxn];
int main()
{
	int T;cin>>T;
	while(T--)
	{
		bool exist[30];memset(exist,0,sizeof(exist));
		int n;cin>>n;scanf("%s",s+1);
		int fg=1;
		for(int i=0;i<=n;++i)
		{
			if(s[i]==s[i-1])continue;
			else 
			{
				if(!exist[s[i]-'A'])exist[s[i]-'A']=1;
				else 
				{
					fg=0;
					break;
				}
			}
		}
		puts(fg?"YES":"NO");
	}
}