
# t=int(input())
#
# for test in range (t):

# t = int(input())
#
#     for test in range(t):
#     x=input()
#     y=x.split()
#     y=[int(y[0]),int(y[1]),int(y[2])]
#     y.sort()
#     if y[1]==y[2]:
#         print('YES')
#         print(y[0],y[0],y[1])
#     else:
#         print('NO')

# t=int(input())
#
# for test in range (t):
#     n=int(input())
#     s=input().split()
#     ans=''
#     # for i in range (n):
#     #     s[i]=int(s[i])
#     seen=[]
#     for i in s:
#         if i in seen:
#             ans+=i
#             ans+=' '
#         else:
#             seen.append(i)
#     print(ans[:-1])

# t=int(input())
#
# for test in range (t):
#     n=int(input())
#     s=input().split()
#     s[-1]=int(s[-1])
#     dec=False
#     found=False
#     for i in range (n-2,-1,-1):
#         s[i]=int(s[i])
#         if dec and s[i]>s[i+1]:
#                 print(i+1)
#                 found=True
#                 break
#         elif s[i]<s[i+1]:
#             dec=True
#     if not found:
#         print(0)

# string.count()

t=int(input())
global s

def cost(n,c,f):
    if n==1:
        if s[f]==c:
            return 0
        else:
            return 1
    half=n//2
    return min(cost(half,chr(ord(c) + 1),f)+half-s[f+half:f+n].count(c),cost(half,chr(ord(c) + 1),f+half)+half-s[f:f+half].count(c))

for test in range (t):
    n=int(input())
    s=input()
    print(cost(n,'a',0))