def find(s,c,k):
    if len(s) == 1:
        if s==c:
            return 0
        else:
            return 1
    # length of s is always 2**k
    # assume 2**k = len(s)
    # c 
    first_half = s[:2**(k-1)]
    second_half = s[2**(k-1):]
    count_first = 0
    count_second = 0
    for x in first_half:
        if x != c:
            count_first += 1
    for x in second_half:
        if x != c:
            count_second += 1
            
    ans1 = count_first + find(second_half,chr(ord(c) + 1),k-1)
    ans2 = count_second + find(first_half,chr(ord(c) + 1),k-1)
    return min(ans1,ans2)

for _ in range(int(input())):
    input()
    s = input()
    for k in range(20):
        if 2**k == len(s):
            break
    print(find(s,"a",k))
    