#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define eb emplace_back
#define F first
#define S second
#define ALL(x) x.begin(), x.end()
#define MEM(x) memset(x, 0, sizeof(x));
#define MEMS(x) memset(x, -1, sizeof(x));

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
/*-------------------------------------------------------------------------*/
/// WHYYYYYYYYYYY INNNNNNNNNNNQUUUUUUUUUEUE
const ll MOD = 1e9 + 7;

inline void solve() {
	int n;  cin >> n;
	set<char> st;
	string str; cin >> str;
	bool ans = 1;
	for(int i = 0; i < n; ++i) {
		while(i + 1 < n && str[i] == str[i + 1])
			++i;
		if(st.count(str[i])) ans = 0;
		st.insert(str[i]);
	}
	cout << (ans ? "YES\n" : "NO\n");
}

signed main() {
	cin.tie(nullptr), cout.tie(nullptr), ios::sync_with_stdio(false);
	int t; cin >> t;
	while(t--)
		solve();
}