#!/usr/bin/env pypy
import sys
input = sys.stdin.readline


def inp():
    return (int(input()))


def inlt():
    return (list(map(int, input().split())))


def insr():
    s = input()
    return (list(s[:len(s) - 1]))


def invr():
    return list((map(int, input().split())))

hash_map = {}


def solve(c, s_list):
    # print(c, s_list)
    if len(s_list) == 1:
        if s_list[0] != c:
            return 1
        return 0
    if (c, tuple(s_list)) in hash_map:
        return hash_map[(c, tuple(s_list))]
    left, right, _min = 0, 0, float('inf')
    mid = int(len(s_list)/2)
    for _i in range(mid):
        if s_list[_i] != c:
            left += 1
    _min = min(_min, left + solve(chr(ord(c) + 1), s_list[mid:]))
    for _i in range(mid):
        if s_list[mid+_i] != c:
            right += 1
    _min = min(_min, right + solve(chr(ord(c) + 1), s_list[:mid]))
    # print(c, s_list, _min)
    hash_map[(c, tuple(s_list))] = _min
    return _min


if __name__ == '__main__':
    t = inp()
    for i in range(t):
        n = inp()
        s = insr()
        print(solve('a', s))
