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

#define LL long long
#define ldb long double
#define debug(a) #a << "=" << a << " "
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const int mod = 998244353;
const int N = 5e5 + 5;
map<int, int> mp;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#ifdef DEBUG
    freopen("1.in", "r", stdin);
    // freopen("1.out", "w", stdout);
#endif
    int T = 1;
   
    cin >> T; //scanf("%d", &T);
    while (T--)
    {
        string s;
        int n, a = 0;
        cin >> n >> s;
        set<char> st;
        for (int i = 0; i < n; i++)
        {
            if (s[i] != s[i + 1])
                a++;
            st.insert(s[i]);
        }
        if(st.size() == a){
            cout << "YES" << endl;
        }else
            cout << "NO" << endl;
        // int n,ans = 0;
        // cin >> n;
        // for(auto x:v){
        //     ans += (x <= n);
        // }
        // cout << ans << endl;
    }
    return 0;
}