#include <iostream>

using namespace std;
string s;
int a,b,c[1001],d[50],j,i;
int main()
{  cin>>a;
  for(j=1;j<=a;j++)
  {cin>>b;
    cin>>s;
    d[int(s[0])-64]++;
for(i=1;i<b;i++)
    if(s[i]!=s[i-1] && d[int(s[i])-64]!=0)
    c[j]=1;
    else if(s[i]!=s[i-1])
d[int(s[i])-64]++;
for(i=1;i<50;i++)
    d[i]=0;
}
for(j=1;j<=a;j++)
    if(c[j]==1)
    cout << "NO" << endl;
else cout<<"YES"<<endl;
    return 0;
}
