def rec(s,low,high,c):
    low = 0
    high = len(s)
    if len(s)==1:
        if s[0]==c:
            return 0
        else:
            return 1
    mid = (low+high)//2
    return min((len(s)//2 - s[low:mid].count(c))+rec(s[mid:high],mid,high,chr(ord(c)+1)),
                (len(s)//2 -s[mid:high].count(c))+rec(s[low:mid],low,mid,chr(ord(c)+1)))
for _ in range(int(input())):
    n = int(input())
    s = input()

    print(rec(s,0,n,'a'))
