from math import log2
for i in range(int(input())):
    n=int(input())
    s=input()
    def fun(s,dept,cr):
        if dept==0:
            if s==chr(cr): #alpha[dept]
                return 0
            else:
                return 1
        n=2**(dept-1)
        ch=chr(cr) #alpha[dept]
        c1=n-s[:n].count(ch)
        c2=n-s[n:].count(ch)
        a=fun(s[:n],dept-1,cr+1)
        b=fun(s[n:],dept-1,cr+1)
        m1=c1+b
        m2=c2+a
        if m1<=m2:
            return m1
        else:
            return m2
    dept=int(log2(n))
    #alpha=[chr(97+i) for i in range(dept+1)]
    #lpha=alpha[::-1]
    print(fun(s,dept,97))
    
            
                    
        
     
                
    
                  
            
