#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		map<char,int>vis;
		int n;
		cin>>n;
		string ch;
		cin>>ch;
		int f=0;
		for(int i=0;i<ch.length()-1;i++)
		{
			if(ch[i]!=ch[i+1])
			{
				vis[ch[i]]++;
			}
			if(vis[ch[i+1]]!=0)
			{
				cout<<"NO\n";
				f=1;
				break;
			}
		}
		if(f==0)
		cout<<"YES\n";
	}
}