blanck=[]
def rec(n,i):
    if n//2==0:
        return
    if n//2==1:
        return chr(i)+chr(i+1)
    else:
        return  chr(i)*(n//2) +rec(n//2,i+1)
def rec4(n,i):
    if n//2==0:
        return
    if n//2==1:
        return chr(i+1)+chr(i)
    else:
        return  rec(n//2,i+1)+ chr(i)*(n//2)



def good(n,s):
    if n==1:
        if s=="a":
            return 0
        else:
            return 1
    temp1=rec(n,ord("a"))
    temp2=rec4(n,ord("a"))
    try:
        temp3=temp1[:n-2]+temp1[n-2:][::-1]
        temp4=temp2[:n//2-2]+temp2[n//2-2:n//2][::-1]+temp2[n//2:]
    except:
        temp3=temp1
        temp4=temp2
    ans=n
    for x in [temp1,temp2,temp3,temp4,temp1[::-1],temp2[::-1],temp4[::-1],temp3[::-1]]:
        base=0
        for j in range(0,n):
            if x[j]!=s[j]:
                base+=1
        ans=min(base,ans)
    return ans

for i in range(int(input())):
    a=int(input())
    s=input()
    print(good(a,s))