#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <stack>
#include <queue>
using namespace std;
int t, n, m;
char p[100];
int check[1000];
int main()
{
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> m;
		scanf("%s", p);
		check[p[0]]++;
		for (int j = 1; j < m; j++)
		{
			if (check[p[j]] != 0 && p[j - 1] != p[j])
			{
				n++;
				break;
			}
			check[p[j]]++;
		}
		if (n > 0)
		{
			printf("NO\n");
		}
		else {
			printf("YES\n");
		}
		n = 0;
		for (int j = 0; j < 1000; j++) check[j] = 0;
	}
	return 0;
}