for x in range(int(input())):
    n = int(input())
    s=input()
    k=65
    def rec(st,k):
        
        n=len(st)
        if n==1:
            
            if st[0]==chr(k).lower():
                
                return 0
            else:
                return 1

        a=n//2-st[n//2:].count(chr(k).lower())+rec(st[:n//2],k+1)
        b=n//2-st[:n//2].count(chr(k).lower())+rec(st[n//2:],k+1)
        
        return min(a,b)
    print(rec(s,65))
        