import sys
sys.setrecursionlimit(10**7)
from functools import lru_cache
@lru_cache(None)
def good(s,start,end,c):
    if start==end:
        if s[start]==c:
            return 0
        else:
            return 1
    if end==start+1:
        if (s[start]==c and s[end]==chr(ord(c)+1)) or (s[end]==c and s[start]==chr(ord(c)+1)) :
            return 0
        if s[start]==c and s[end]!=chr(ord(c)+1):
            return 1
        if s[start]!=chr(ord(c)+1) and s[end]==c:
            return 1
        if s[start]==chr(ord(c)+1):
            return 1
        if s[end]==chr(ord(c)+1):
            return 1
        return 2
    mid=(start+end)//2
    count1,count2=0,0
    for i in range(start,mid+1):
        if s[i]!=c:
            count1+=1
    for i in range(mid+1,end+1):
        if s[i]!=c:
            count2+=1
    next=chr(ord(c)+1)
    return min(count1+good(s,mid+1,end,next),count2+good(s,start,mid,next))
def string(s):
    c='a'
    start=0
    end=len(s)-1
    return good(s,start,end,c)
t=int(input())
for i in range(t):
    n=int(input())
    s=input()
    print(string(s))