def solve(s,n):
    fa,la,z=0,0,n//2
    for i in range(z):
        if s[i]=='a':fa+=1
        if s[n-i-1]=='a':la+=1
    if fa>la:
        s=s[z:]
        ans=z-fa
    else:
        s=s[:z]
        ans=z-la
    fa,la,k=0,0,z//2
    for i in range(k):
        if s[i]=='b':fa+=1
        if s[z-i-1]=='b':la+=1
    ans+=(k-max(fa,la))
    print(ans)
t=int(input())
for i in range(t):
    n,s=int(input()),input()
    if n==1:
        if s=='a':print(0)
        else:print(1)
    else:
        solve(s,n)
    