
#include <bits/stdc++.h>

using namespace std;

void code()
{
	int n;
	cin>>n;
	string s;
	cin>>s;

	set<char> used;
	char last='-';
	bool possible=true;
	for(char& c:s)
	{
		if(c!=last)
		{
			if(used.find(c)!=used.end())
			{
				possible=false;
				break;
			}
		}
		last=c;
		used.insert(c);
	}

	if(possible)
		cout<<"YES";
	else
		cout<<"NO";
	cout<<"\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int t=1;
	cin>>t;
	for(int tt=1;tt<=t;++tt)
	{
		code();
	}

	return 0;
}
