#include<bits/stdc++.h>
using namespace std;
//ofstream filee("output8.txt");
//ifstream file("input8.txt");
void solve()
{
//string s;
//while(file >> s)
int n; cin>>n;
string s; cin>>s;
int a[n][26]={0};
int b[26]={0};
for(int i=0;i<n;i++)
{
b[s[i]-'a']++;
for(int j=0;j<26;j++)
{
a[i][j]=b[j];
}
}
int ans=0;
for(int i=0;i<n;i++)
{
int point = s[i]-'a';
for(int j=0;j<26;j++)
{
if(j==point) continue;
if(a[i][j]!=0 && a[i][j]*2==b[j])
{
ans++;
break;
}
}
}
//filee<<ans<<endl;
cout<<ans<<endl;
//cout<<s<<endl;
}
int main(){
int t; cin>>t; while(t--) solve();
//file.close();
//filee.close();
}