#include <bits/stdc++.h>
 
using namespace std;
 
#define speed                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);                   \
	cout.tie(0);
#define _ << " " <<
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define F first
#define S second
#define pb push_back
 
const int INF = 1000000007;
const int mx = 300010;

ll a[mx], was[50];

int main() {
	speed;
	int T;
	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		string s;
		cin >> s;
		bool good = 1;
		for (int i = 0; i < n; ++i) {
			if (was[s[i] - 'A'] == 1) {
				good = 0;
			}
			was[s[i] - 'A'] = 1;
			while (s[i + 1] == s[i] && i + 1 <= n) {
				i++;
			}
		}
		if (good) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}
		memset(was, 0, sizeof(was));
	}
}