﻿//#pragma warning(disable : 4996)
#include <stdio.h>
#include <stdlib.h>
int main() {
	//int result[1000] = { 0 };
	int result[1000] = { 0 };
	int num,t;
	char str[50];
	scanf("%d", &t);
	for (int i = 0; i < t*2; i++) {
		if(i%2==0) 
			scanf("%d", &num);
		else 
			scanf("%s", str);
		if ((i + 1) % 2 == 0) {
			int* ch = (int*)calloc(50, sizeof(int));
			for (int j = 0; j < num; j++) {
				if (ch[str[j] - 'A'] == 1 && str[j - 1] != str[j]) {
					result[i/2] = 1;
				}
				else {
					ch[str[j] - 'A'] = 1;
				}
			}
		}
		
	}
	for (int i = 0; i < t; i++) {
		if (result[i] == 0)
			printf("Yes\n");
		else
			printf("NO\n");
	}
}
