from math import log2
for _ in range(int(input())):
    l = int(input())
    s = input()
    k = int(log2(l))
    news = [0] * (l)
    for i in range(l):
        news[i] = ord(s[i]) - 97
    dis = []
    
    for i in range(k + 1):
        dis.append(2 ** (k - i))
    def dpg(alph , st):
        if alph == k:
            if news[st] == alph:
                return 0
            else:
                return 1
        cost1 ,cost2 = 0 , 0
        for i in range(st , st + dis[alph]):
            if i < st + dis[alph] / 2:
                if news[i] != alph:
                    cost1 += 1
            else:
                if news[i] != alph:
                    cost2 += 1
        return min(dpg(alph + 1 , st) + cost2 \
            , dpg(alph + 1 , st + dis[alph + 1]) + cost1)
    print(dpg(0 , 0))