import string

for i in range(int(input())):
    n = int(input())
    s = input()

    pch = 0

    l = 0
    r = n - 1

    count = 0

    while l != r:
        m = l + (r - l + 1) // 2
        la = [0] * 27
        rb = [0] * 27

        for i in range(l, m):
            if s[i] == string.ascii_lowercase[pch]:
                la[ord(s[i]) - ord("a")] += 1
            if s[i] > string.ascii_lowercase[pch]:
                la[ord(s[i]) - ord("a")] -= 1

        for i in range(m, r + 1):
            if s[i] == string.ascii_lowercase[pch]:
                rb[ord(s[i]) - ord("a")] += 1
            if s[i] > string.ascii_lowercase[pch]:
                rb[ord(s[i]) - ord("a")] -= 1

        if la > rb:
            count += (r - l + 1) // 2 - la[pch]
            l = m
        else:
            count += (r - l + 1) // 2 - rb[pch]
            r = m - 1

        pch += 1

    if s[l] != string.ascii_lowercase[pch]:
        count += 1

    print(count)