https://codeforces.com/problemset/problem/1791/D
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*4;
int t,cnt1[N],cnt2[N];
int main(void)
{
cin>>t;
while(t--)
{
int len; cin>>len;
string s; cin>>s;
for(int i=1;i<=len;i++) cnt1[i]=0,cnt2[i]=0;
set<char>st1,st2;
s="0"+s;
int ans=0;
for(int i=1;i<=len;i++) st1.insert(s[i]),cnt1[i]=st1.size();
for(int i=len;i>=1;i--) st2.insert(s[i]),cnt2[i]=st2.size();
for(int i=1;i<len;i++)
{
ans=max(ans,cnt1[i]+cnt2[i+1]);
}
cout<<ans<<endl;
}
return 0;
}