ans = 0
def test(n,string,index):
    global ans
    if(len(n)>1):
        if(len(n)!=n.count(string[index])):
            tag = n[:len(n)//2].count(string[index])
            tag1 = n[len(n)//2:].count(string[index])
            if(tag==0 and tag1==0):
                ans+=len(n)//2
                tag = n[:len(n)//2].count(string[index+1])
                tag1 = n[len(n)//2:].count(string[index+1])
                if(tag>tag1):
                    ans+=len(n)//2-tag
                    test(n[len(n)//2:],string,index+1)
                else:
                    ans+=len(n)//2-tag1
                    test(n[:len(n)//2],string,index+1)
            elif(tag>tag1):
                ans+=len(n)//2-tag
                test(n[len(n)//2:],string,index+1)
            else:
                ans+=len(n)//2-tag1
                test(n[:len(n)//2],string,index+1)
    else:
        if(len(n)!=n.count(string[index])):
            tag = n[:len(n)//2].count(string[index])
            tag1 = n[len(n)//2:].count(string[index])
            if(tag==0 and tag1==0):
                ans+=len(n)
                tag = n[:len(n)//2].count(string[index+1])
                tag1 = n[len(n)//2:].count(string[index+1])
                if(tag>tag1):
                    ans+=len(n)-tag
                    test(n[len(n)//2:],string,index+1)
                else:
                    ans+=len(n)-tag1
                    test(n[:len(n)//2],string,index+1)
            elif(tag>tag1):
                ans+=len(n)-tag
                test(n[len(n)//2:],string,index+1)
            else:
                ans+=len(n)-tag1
                test(n[:len(n)//2],string,index+1)
a = input()
for x in range(int(a)):
    c = input()
    b = input()
    ans = 0
    string = "abcdefghijklmnopqrstuvwxyz"
    ans1 = len(b)-b.count("a")
    if(len(b)==b.count("a")):
        print(0)
    else:
        test(b,string,0)
        print(min(ans1,ans))