import sys, collections
def get_mic(left, right, num):
    if left == right:
        return 1 if string[left] != chr(num) else 0
    mid = (left + right) // 2
    l_cnt = 0
    r_cnt = 0
    for i in range(mid + 1, right + 1):
        if string[i] != chr(num):
            l_cnt += 1
    for i in range(mid, -1, -1):
        if string[i] != chr(num):
            r_cnt += 1
    return min(l_cnt + get_mic(left, mid, num + 1), r_cnt + get_mic(mid + 1, right, num + 1))



tc = int(sys.stdin.readline())
for _ in range(tc):
    n = int(sys.stdin.readline())
    string = sys.stdin.readline().rstrip()
    print(get_mic(0, len(string) - 1, 97))