#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 17 21:09:50 2020

@author: kshitiz
"""


def good(s, k, el, cost, record):
    
    # print(s, k, el, cost, record)
    if len(s)==1:
        if s==el:
            record.append(cost)
        else:
            record.append(cost+1)
        return 0
    
    nxt = chr(ord(el)+1)
    k1 = k-1
    
    left = 0; right = 0
    for i in range(2**k1):
        if s[i]==el:
            left+=1
    for i in range(2**k1, 2**k):
        if s[i]==el:
            right+=1
    
    if left==right:
        c1 = cost + (2**k1 - left)
        good(s[:2**k1], k1, nxt, c1, record)
        good(s[2**k1:], k1, nxt, c1, record)
    
    else:
        if left>right:
            if left>2**(k1-1):
                c2 = cost + (2**k1 - left)
                good(s[2**k1:], k1, nxt, c2, record)
            else:
                c3 = cost + (2**k1 - right)
                c4 = cost + (2**k1 - left)
                good(s[:2**k1], k1, nxt, c3, record)
                good(s[2**k1:], k1, nxt, c4, record)
        else:
            if right>2**(k1-1):
                c2 = cost + (2**k1 - right)
                good(s[:2**k1], k1, nxt, c2, record)
            else:
                c3 = cost + (2**k1 - right)
                c4 = cost + (2**k1 - left)
                good(s[:2**k1], k1, nxt, c3, record)
                good(s[2**k1:], k1, nxt, c4, record)
    
    return 0

import math

t = int(input())

for _ in range(t):
    
    n = int(input())
    
    k = int(math.log(n, 2))
    
    s = input()
    
    rec = []
    good(s, k, 'a', 0, rec)
    
    print(min(rec))