rt
#include<bits/stdc++.h>
using namespace std;
bool bsy(char x){
if(x=='A'||x=='T'||x=='C'||x=='G')
return false;
return true;
}
bool work(char x,char y){
if(x=='A'&&y=='T')
return true;
if(x=='T'&&y=='A')
return true;
if(x=='C'&&y=='G')
return true;
if(x=='G'&&y=='C')
return true;
return false;
}
int t,n;
char s[100002];
int main(){
scanf("%d",&t);
while(t--){
bool b=false;
scanf("%d%s",&n,s+1);
for(int i=1;i<=n;i++)
if(bsy(s[i])){
b=true;
printf("0\n");
break;
}
if(b)
continue;
int ans=0;
for(int i=1;i<=n/2;i++)
if(work(s[i],s[n-i+1]))
ans+=n+1;
printf("%d\n",ans);
}
}