import java.io.*;
import java.util.*;
import static java.lang.Math.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class CodeChef {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(in.nextInt(), in, out);
        out.close();
    }
    static class TaskA {
        long mod = (long)(1000003);
        long fact[];
        int depth[];
        int parentTable[][];
        int degree[];
        ArrayList<Integer> leaves;

        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            while(testNumber-->0){
                int n = in.nextInt();
                String s = in.next();
                int min = Integer.MAX_VALUE;
                int tree[][] = new int[4*n][];
                build(tree , s , 0 , n-1 , 0);
                // out.println(query(tree , 0 , n-1 , 0 , ))
                out.println(ans(s , tree , 0 , n-1 , 0));
            }
        }

        public int ans(String s , int tree[][] , int start , int end , int count){
            if(start == end){
                if(s.charAt(start) - 'a' == count)
                    return 0;
                else 
                    return 1;
            }
            int mid = (start+end+1)>>1;
            int result = Integer.MAX_VALUE;
            //first half
            int x = (mid-start) - query(tree , 0 , s.length()-1 , start , mid-1 , 0 , count);
            // System.out.println(start + " " + mid + " " + x);

            result = min(result , x + ans(s , tree , mid , end , count+1));

            // result = min(result , x + ans(tree , 0 , s.length()-1 , mid , end , 0 , count+1));

            int y = (end-mid+1) - query(tree , 0 , s.length()-1 , mid , end , 0 , count);
            // System.out.println((mid) + " " + end + " " + y);
            // result = min(result , y + ans(tree , 0 , s.length()-1 , start , mid-1 , 0 , count+1));

            result = min(result , y + ans(s , tree , start , mid-1 , count+1));

            return result;

        }

        public int query(int tree[][] , int tl , int th , int ql , int qh , int pos , int count){
            if(ql<=tl && qh>=th)
                return tree[pos][count];
            if(ql>th || qh<tl)
                return 0;
            int mid = (tl+th)>>1;
            int left = query(tree , tl , mid , ql , qh , 2*pos+1 , count);
            int right = query(tree , mid+1 , th , ql , qh , 2*pos+2 , count);
            return left+right;
        }

        public int[] merge(int left[] , int right[]){
            int parent[] = new int[26];
            for(int i=0;i<26;i++)
                parent[i] = left[i] + right[i];
            return parent;
        }

        public void build(int tree[][] , String s , int low , int high , int pos){
            if(low == high){
                tree[pos] = new int[26];
                tree[pos][s.charAt(low)-'a']++;
                return;
            }
            int mid = (low+high)>>1;
            build(tree , s , low , mid , 2*pos+1);
            build(tree , s , mid+1 , high , 2*pos+2);
            tree[pos] = merge(tree[2*pos+1] , tree[2*pos+2]);
        }

        class Pair{
            int x;
            int y;
            public Pair(int x , int y){
                this.x = x;
                this.y = y;
            }
        }

        class Sort implements Comparator<Pair>{
            public int compare(Pair a , Pair b){
                if(a.x<b.x)
                    return -1;
                else if(a.x == b.x && a.y<b.y)
                    return -1;
                return 1;
            }
        }

        public int findSet(int parent[] , int x){
            if(parent[x]<0)
                return x;
            int y = findSet(parent , parent[x]);
            parent[x] = y;
            return y;
        }

        // for printing purposes
        public void print1d(int a[] , PrintWriter out){
            for(int i=0;i<a.length;i++)
                out.print(a[i] + " ");
            out.println();
        }

        public void print2d(long a[][] , PrintWriter out){
            for(int i=0;i<a.length;i++){
                for(int j=0;j<a[i].length;j++)
                    out.print(a[i][j] + " ");
                out.println();
            }
            out.println();
        }
        public void sieve(int a[]){
            a[0] = a[1] = 1;
            int i;
            for(i=2;i*i<=a.length;i++){
                if(a[i] != 0)
                    continue;
                a[i] = i;
                for(int k = (i)*(i);k<a.length;k+=i){
                    if(a[k] != 0)
                        continue;
                    a[k] = i;
                }
            }
        }
        
        public long pow(long a, long b, long m) {
            a %= m;
            long res = 1;
            while (b > 0) {
                long x = b&1;
                if (x == 1)
                    res = res * a % m;
                a = a * a % m;
                b >>= 1;
            }
            return res;
        }
        public long pow(long a, long b) {
            long res = 1;
            while (b > 0) {
                long x = b&1;
                if (x == 1)
                    res = res * a;
                a = a * a;
                b >>= 1;
            }
            return res;
        }
        
        public void sortedArrayToBST(TreeSet<Integer> a , int start, int end) { 
            if (start > end) {
                return;
            }
            int mid = (start + end) / 2;
            a.add(mid);
            sortedArrayToBST(a, start, mid - 1);
            sortedArrayToBST(a, mid + 1, end); 
        }

        public int lowerLastBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>=x)
                return -1;
            if(a.get(r)<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid-1)<x)
                    return mid-1;
                else if(a.get(mid)>=x)
                    r = mid-1;
                else if(a.get(mid)<x && a.get(mid+1)>=x)
                    return mid;
                else if(a.get(mid)<x && a.get(mid+1)<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(ArrayList<Integer> a , Integer x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>x)
                return l;
            if(a.get(r)<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid+1)>x)
                    return mid+1;
                else if(a.get(mid)<=x)
                    l = mid+1;
                else if(a.get(mid)>x && a.get(mid-1)<=x)
                    return mid;
                else if(a.get(mid)>x && a.get(mid-1)>x)
                    r = mid-1;
            }
            return mid;
        }
        public int lowerLastBound(int a[] , int x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>=x)
                return -1;
            if(a[r]<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid-1]<x)
                    return mid-1;
                else if(a[mid]>=x)
                    r = mid-1;
                else if(a[mid]<x && a[mid+1]>=x)
                    return mid;
                else if(a[mid]<x && a[mid+1]<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(long a[] , long x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>x)
                return l;
            if(a[r]<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid+1]>x)
                    return mid+1;
                else if(a[mid]<=x)
                    l = mid+1;
                else if(a[mid]>x && a[mid-1]<=x)
                    return mid;
                else if(a[mid]>x && a[mid-1]>x)
                    r = mid-1;
            }
            return mid;
        }
        public long log(float number , int base){
            return (long) Math.ceil((Math.log(number) / Math.log(base)) + 1e-9);
        }
        public long gcd(long a , long b){
            if(a<b){
                long c = b;
                b = a;
                a = c;
            }
            while(b!=0){
                long c = a;
                a = b;
                b = c%a;
            }
            return a;
        }
        public long[] gcdEx(long p, long q) {
            if (q == 0)
                return new long[] { p, 1, 0 };
            long[] vals = gcdEx(q, p % q);
            long d = vals[0];
            long a = vals[2];
            long b = vals[1] - (p / q) * vals[2];
            // 0->gcd 1->xValue 2->yValue
            return new long[] { d, a, b };
        }
        public void sievePhi(int a[]){
            a[0] = 0;
            a[1] = 1;
            for(int i=2;i<a.length;i++)
                a[i] = i-1;
            for(int i=2;i<a.length;i++)
                for(int j = 2*i;j<a.length;j+=i)
                    a[j] -= a[i];
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}
