#include<bits/stdc++.h>
using namespace std;
void solve()
{
	int n;cin >> n;
	string a;cin >> a;
	string b = "";
	for(int i =0;i<n-1;i++)
	{
		if(a[i] != a[i+1])
		{
			b += a[i];
		}
	}
	b += a[n-1];
	array<vector<int>,26> arr;
	for(int i = 0;i<b.size();i++)
	{
		arr[b[i] - 'A'].push_back(i);
	}
	for(auto &e : arr)
	{
		if(e.size() >= 2)
		{
			cout << "NO" << "\n";
			return;
		}
	}
	cout << "YES" << "\n";
	return;
}
int main()
{
	iostream::sync_with_stdio(false);cin.tie(NULL);
	int t;cin >> t;
	while(t--)
	{
		solve();
	}
}
