#include <bits/stdc++.h>
using namespace std;
class covid
{
    public:
    string res;
    void calc()
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
       // set<string, greater<string> > s1;
        int i=0;
        res="YES";
        while(i<n)
        {
        	//cout<<i<<endl;
            int element=s[i];
            if(i+1<n)
            {
            if(s[i]==s[i+1])
            {
                i++;
            }
            else
            {
                for(int j=i+1;j<n;j++)
                {
                    if(s[j]==element)
                    {
                    res="NO";
                    return;
                }
                
            }
            i++;
        }
        
        
    }
	else{
		break;
	}}
    
    
}};

int main() {
    
    int t; //testcases
    cin>>t;
    covid obj[t];
    for(int i=0;i<t;i++)
    {
        obj[i].calc();
    }
    for(int i=0;i<t;i++)
    {
        cout<<obj[i].res<<endl;
    }
    
}

