def getCost(s, ch):
    return len(s) - s.count(chr(ch))
    
def getMin(s, h, l=0, alpha = 97):
    if h - l == 1:
        if s[l:h] == chr(alpha): return 0
        return 1
    mid = (l + h) // 2

    return min(getCost(s[l:mid], alpha) + getMin(s, h, mid, alpha+1),
               getCost(s[mid:h], alpha) + getMin(s, mid, l, alpha+1))
    
for _ in range(int(input())):  
    n = int(input())
    s = input()
    print(getMin(s,  n))



    
    


