import java.util.*;
import java.io.*;
import java.math.*;

public class Main {

    private static FastReader fr = new FastReader();
    private static Helper hp = new Helper();
    private static StringBuilder result = new StringBuilder();

    public static void main(String[] args) {
        Task solver = new Task();
        solver.solve();
    }

    static class Task {

        private int helper(String s, char ch){
            if(s.length() == 0) return 0;
            if(s.length() == 1){
                if(s.charAt(0) == ch) return 0;
                return 1;
            }
            int countLeft =0, countRight = 0;
            for(int i=0; i<s.length()/2; i++) if(s.charAt(i) == ch) countLeft++;
            for(int i=s.length()/2; i<s.length(); i++) if(s.charAt(i) == ch) countRight++;

            int op1 = helper(s.substring(0, s.length()/2), (char)(ch + 1)) + (s.length()/2 - countRight);
            int op2 = (s.length()/2 - countLeft) + helper(s.substring(s.length()/2), (char)(ch + 1));

            return Math.min(op1, op2);
        }

        public void solve() {
            int nt = fr.ni();
            while(nt-- > 0){
                int n = fr.ni();
                String s = fr.next();
                int ans = helper(s, 'a');
                result.append(ans).append("\n");
            }
            System.out.println(result);
        }
    }

    static class Helper {
        public int[] ipArrInt(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = fr.ni();
            return arr;
        }

        public long[] ipArrLong(int n, int si) {
            long[] arr = new long[n];
            for (int i = si; i < n; i++)
                arr[i] = fr.nl();
            return arr;
        }
    }

    static class FastReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        private static PrintWriter pw;

        public FastReader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
            pw = new PrintWriter(System.out);
            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 ni() {
            return Integer.parseInt(next());
        }

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

        public double nd() {
            return Double.parseDouble(next());
        }

        public String rl() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        public void print(String str) {
            pw.print(str);
            pw.flush();
        }
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class Main {

    private static FastReader fr = new FastReader();
    private static Helper hp = new Helper();
    private static StringBuilder result = new StringBuilder();

    public static void main(String[] args) {
        Task solver = new Task();
        solver.solve();
    }

    static class Task {

        private long helper(String s, char ch, int n){
            if(n == 1 && s.charAt(0) == ch) return 0;
            if(n == 1 && s.charAt(0) != ch) return 1;
            StringBuilder sb = new StringBuilder();
            for(int i=0; i<n/2; i++) sb.append(ch);
            String newStr = sb.toString();
            long op1 = 0, op2 = 0;
            long ans1 = helper(s.substring(n/2, n), (char)(ch+1), n/2);
            long ans2 = helper(s.substring(0, n/2), (char)(ch+1), n/2);
            if(s.substring(0, n/2).equals(newStr)){
                op1 = ans1;
            }
            else{
                for(int i=0; i<n/2; i++){
                    if(s.charAt(i) != newStr.charAt(i)) op1 += 1;
                }
                op1 += ans1;
            }
            if(s.substring(n/2, n).equals(newStr.toString())){
                op2 = ans2;
            }
            else{
                for(int i=n/2, j=0; i<n; ++i, ++j){
                    if(s.charAt(i) != newStr.charAt(j)) op2 += 1;
                }
                op2 += ans2;
            }
            return Math.min(op1, op2);
        }

        public void solve() {
            int nt = fr.ni();
            while(nt-- > 0){
                int n = fr.ni();
                String s = fr.next();
                long ans = helper(s, 'a', n);
                result.append(ans).append("\n");
            }
            System.out.println(result);
        }
    }

    static class Helper {
        public int[] ipArrInt(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = fr.ni();
            return arr;
        }

        public long[] ipArrLong(int n, int si) {
            long[] arr = new long[n];
            for (int i = si; i < n; i++)
                arr[i] = fr.nl();
            return arr;
        }
    }

    static class FastReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        private static PrintWriter pw;

        public FastReader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
            pw = new PrintWriter(System.out);
            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 ni() {
            return Integer.parseInt(next());
        }

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

        public double nd() {
            return Double.parseDouble(next());
        }

        public String rl() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        public void print(String str) {
            pw.print(str);
            pw.flush();
        }
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class Main {

    private static FastReader fr = new FastReader();
    private static Helper hp = new Helper();
    private static StringBuilder result = new StringBuilder();

    public static void main(String[] args) {
        Task solver = new Task();
        solver.solve();
    }

    static class Task {

        private int helper(String s, char ch){
            if(s.length() == 0) return 0;
            if(s.length() == 1){
                if(s.charAt(0) == ch) return 0;
                return 1;
            }
            int countLeft =0, countRight = 0;
            for(int i=0; i<s.length()/2; i++) if(s.charAt(i) == ch) countLeft++;
            for(int i=s.length()/2; i<s.length(); i++) if(s.charAt(i) == ch) countRight++;
            int moves = 0;
            if(countLeft == 0 & countRight == 0){
                int nextLeft = 0, nextRight = 0;
                char nextChar = (char) (ch + 1);
                for(int i=0; i<s.length()/2; i++) if(s.charAt(i) == nextChar) nextLeft++;
                for(int i=s.length()/2; i<s.length(); i++) if(s.charAt(i) == nextChar) nextRight++;
                moves += s.length()/2;
                if(nextLeft == nextRight){
                    moves += helper(s.substring(s.length()/2), nextChar);
                }
                else if(nextLeft > nextRight){
                    moves += helper(s.substring(0, s.length()/2), nextChar);
                }
                else{
                    moves += helper(s.substring(s.length()/2), nextChar);
                }
            }
            else if(countLeft >= countRight){
                moves += (s.length()/2 - countLeft);
                moves += helper(s.substring(s.length()/2), (char)(ch + 1));
            }
            else{
                moves += (s.length()/2 - countRight);
                moves += helper(s.substring(0, s.length()/2), (char)(ch+1));
            }
            return moves;
        }

        public void solve() {
            int nt = fr.ni();
            while(nt-- > 0){
                int n = fr.ni();
                String s = fr.next();
                int ans = helper(s, 'a');
                result.append(ans).append("\n");
            }
            System.out.println(result);
        }
    }

    static class Helper {
        public int[] ipArrInt(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = fr.ni();
            return arr;
        }

        public long[] ipArrLong(int n, int si) {
            long[] arr = new long[n];
            for (int i = si; i < n; i++)
                arr[i] = fr.nl();
            return arr;
        }
    }

    static class FastReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        private static PrintWriter pw;

        public FastReader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
            pw = new PrintWriter(System.out);
            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 ni() {
            return Integer.parseInt(next());
        }

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

        public double nd() {
            return Double.parseDouble(next());
        }

        public String rl() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        public void print(String str) {
            pw.print(str);
            pw.flush();
        }
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class Main {

    private static FastReader fr = new FastReader();
    private static Helper hp = new Helper();
    private static StringBuilder result = new StringBuilder();

    public static void main(String[] args) {
        Task solver = new Task();
        solver.solve();
    }

    static class Task {

        private int helper(String s, char ch){
            if(s.length() == 0) return 0;
            if(s.length() == 1){
                if(s.charAt(0) == ch) return 0;
                return 1;
            }
            int countLeft =0, countRight = 0;
            for(int i=0; i<s.length()/2; i++) if(s.charAt(i) == ch) countLeft++;
            for(int i=s.length()/2; i<s.length(); i++) if(s.charAt(i) == ch) countRight++;
            int moves = 0;
            if(countLeft == 0 && countRight == 0){
                moves += s.length()/2;
                int op1 = helper(s.substring(0, s.length()/2), (char)(ch + 1));
                int op2 = helper(s.substring(s.length()/2), (char)(ch + 1));
                moves += Math.min(op1, op2);
            }
            else if(countLeft >= countRight){
                moves += (s.length()/2 - countLeft);
                moves += helper(s.substring(s.length()/2), (char)(ch + 1));
            }
            else{
                moves += (s.length()/2 - countRight);
                moves += helper(s.substring(0, s.length()/2), (char)(ch+1));
            }
            return moves;
        }

        public void solve() {
            int nt = fr.ni();
            while(nt-- > 0){
                int n = fr.ni();
                String s = fr.next();
                int ans = helper(s, 'a');
                result.append(ans).append("\n");
            }
            System.out.println(result);
        }
    }

    static class Helper {
        public int[] ipArrInt(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = fr.ni();
            return arr;
        }

        public long[] ipArrLong(int n, int si) {
            long[] arr = new long[n];
            for (int i = si; i < n; i++)
                arr[i] = fr.nl();
            return arr;
        }
    }

    static class FastReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        private static PrintWriter pw;

        public FastReader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
            pw = new PrintWriter(System.out);
            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 ni() {
            return Integer.parseInt(next());
        }

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

        public double nd() {
            return Double.parseDouble(next());
        }

        public String rl() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        public void print(String str) {
            pw.print(str);
            pw.flush();
        }
    }
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    static String s="";
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in=new Scanner(System.in);
		int t=in.nextInt();
		while(t--!=0)
		{
		    int n=in.nextInt();
		    s=in.next();
		    Codechef obj=new Codechef();
		    int q=obj.f(0,n,'a');
		    System.out.println(q);
		}
	}
	int f(int l,int r,char c)
	{
	    if(r-l==1)
	    {
	        if(s.charAt(l)==c)
	        return 0;
	        else
	        return 1;
	    }
	    int p1=0;
	    int p=0;
	    //System.out.println(q+"uy");
	    for(int i=l;i<r;i++)
	    {
	        if(s.charAt(i)==c && i<(l+r)/2)
	        p++;
	        else if(s.charAt(i)==c && i>=(l+r)/2)
	        p1++;
	    }
	    if(p1>p)
	    return f(l,(l+r)/2,(char)((int)c+1))+(r-l)/2-p1;
	    else if(p>p1)
	    return f((l+r)/2,r,(char)((int)c+1))+(r-l)/2-p;
	    else
	    return Math.min(f(l,(l+r)/2,(char)((int)c+1)),f((l+r)/2,r,(char)((int)c+1)))+(r-l)/2-p;
	}
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    static String s="";
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in=new Scanner(System.in);
		int t=in.nextInt();
		while(t--!=0)
		{
		    int n=in.nextInt();
		    s=in.next();
		    Codechef obj=new Codechef();
		    int q=obj.f(0,n,'a');
		    System.out.println(q);
		}
	}
	int f(int l,int r,char c)
	{
	    if(r-l==1)
	    {
	        if(s.charAt(l)==c)
	        return 0;
	        else
	        return 1;
	    }
	    int p1=0;
	    int p=0;
	    for(int i=l;i<r;i++)
	    {
	        if(s.charAt(i)==c && i<(l+r)/2)
	        p++;
	        else if(s.charAt(i)==c && i>=(l+r)/2)
	        p1++;
	    }
	    return Math.min(f(l,(l+r)/2,(char)((int)c+1))+(r-l)/2-p1,f((l+r)/2,r,(char)((int)c+1))+(r-l)/2-p);
	}
}


import java.util.*;
import java.io.*;
//import java.math.*;

public class Task{
        //  ..............code begins here..............

static long mod=(long)998244353;
static int res=998244353;
static String ss="abcdefghijklmnopqrstuvwxyz";
static void rec(char[] c, int c1,int i,int j,int tmp){
	char cc=ss.charAt(c1);
	if(i==j){
		if(c[i]!=cc) tmp++;
		res=Math.min(res,tmp);
		return;
	}
	int k=(i+j)/2,tc=0,tc1=0;
	for(int x=i;x<=k;x++) if(c[x]!=cc) tc++;
	for(int x=k+1;x<=j;x++) if(c[x]!=cc) tc1++;
	rec(c,c1+1,i,k,tc1+tmp);rec(c,c1+1,k+1,j,tmp+tc);
}
static void solve() throws  IOException {
			int n=int_v(read()); res=998244353;
			char[] c=read().toCharArray();
			rec(c,0,0,n-1,0);
			out.write(res+"\n");
}
public static void main(String[] args) throws  IOException{
                assign();
                int t=int_v(read());
                while(t--!=0) solve();
                out.flush();
}

// taking inputs
static long pow1(long a,int p){long res=1;while(p>0){if((p&1)!=0){res=(res*a);}p >>=1;a=(a*a);}return res;}

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static void sort(int[] a){List<Integer> l=new ArrayList<>();for(int x:a){l.add(x);}Collections.sort(l);for(int i=0;i<a.length;i++){a[i]=l.get(i);}}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
//static String setpreciosion(double d,int k){BigDecimal d1 = new BigDecimal(Double.toString(d));return d1.setScale(k,RoundingMode.HALF_UP).toString();}//UP DOWN HALF_UP
static int gcd(int a,int b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res%m;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
//static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
//static long[] f;
}


import java.util.*;
import java.io.*;

public class CF1385D {
	static FastReader in = new FastReader();

	public static void main(String[] args) {
		int t = in.nextInt();
		while(t-- > 0) solve();
	}

	static void solve() {
		String[] alph = "abcdefghijklmnopqrstuvwxyz".split("");
		int n = in.nextInt();
		String s = in.nextLine();
		if(n == 1)
		{
			if(s.equals("a")) System.out.println(0);
			else System.out.println(1);
			return;
		}

		System.out.println(find(s, 'a'));

	}

	static long find(String s, char c)
	{
		if(s.length() == 1)
		{
			return s.charAt(0) == c ? 0 : 1;
		}
		String left = s.substring(0, s.length() / 2);
        String right = s.substring(s.length() / 2);
        long n_left = numbetween(left.split(""), String.valueOf(c));
        long n_right = numbetween(right.split(""), String.valueOf(c));
        return Math.min(n_right + find(left, (char)(c + 1)), n_left  + find(right, (char)(c + 1)));

	}

	static int numbetween(String[] arr, String a)
	{
		int count = 0;

		for(int i = 0; i < arr.length; i++)
		{
			if(arr[i].equals(a)) count++;
		}

		return arr.length - count;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


import java.util.*;
import java.io.*;

public class CF1385D {
	static FastReader in = new FastReader();

	public static void main(String[] args) {
		int t = in.nextInt();
		while(t-- > 0) solve();
	}

	static void solve() {
		String[] alph = "abcdefghijklmnopqrstuvwxyz".split("");
		int n = in.nextInt();
		String s = in.nextLine();
		if(n == 1)
		{
			if(s.equals("a")) System.out.println(0);
			else System.out.println(1);
			return;
		}

		System.out.println(find(s, 'a'));

	}

	static long find(String s, char c)
	{
		if(s.length() == 1)
		{
			return s.charAt(0) == c ? 0 : 1;
		}
		String left = s.substring(0, s.length() >> 1);
        String right = s.substring(s.length() >> 1);
        long n_left = Arrays.stream(left.split("")).filter(v -> v.charAt(0) != c).count();
        long n_right = Arrays.stream(right.split("")).filter(v -> v.charAt(0) != c).count();
        return Math.min(n_right + find(left, (char)((int)c + 1)), n_left  + find(right, (char)((int)c + 1)));

	}

	static int numbetween(int start, int end, String[] arr, String a)
	{
		int count = 0;
		if(start == end) if(arr[start].equals(a)) count++;

		for(int i = start; i < end; i++)
		{
			if(arr[i].equals(a)) count++;
		}

		return count;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


import java.util.*;
import java.lang.*;

public class Main
{
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        while ( t-- > 0 ) {
            int n = scanner.nextInt();
            String s = scanner.next();
            System.out.println( calculateAnswer(n, s, 0) );
        }
    }

    private static int calculateAnswer(int n, String s, int iterationNo) {
        if (n==1) {
            if (s.charAt(0) == 'a' + iterationNo) return 0;
            else return 1;
        }
        int firstHalf = 0;
        int secondHalf = 0;
        for (int i=0; i<n/2; i++) {
            int charAsNumber = s.charAt(i) - 'a' - iterationNo;
            if (charAsNumber == 0)
                firstHalf++;
        }
        for (int i=n/2; i<n; i++) {
            int charAsNumber = s.charAt(i) - 'a' - iterationNo;
            if (charAsNumber == 0)
                secondHalf++;
        }
        int temp1 = (n/2 - firstHalf) + calculateAnswer(n/2, s.substring(n/2), iterationNo+1);
        int temp2 = (n/2 - secondHalf) + calculateAnswer(n/2, s.substring(0, n/2), iterationNo+1);
        return Math.min(temp1, temp2);
    }

}


import java.util.*;
import java.lang.*;

public class Main
{
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        while ( t-- > 0 ) {
            int n = scanner.nextInt();
            String s = scanner.next();
            int iterationNo = 0;
            int ans = 0;
            ans = calculateAnswer(n, s, iterationNo);
            System.out.println(ans);
        }
    }

    private static int calculateAnswer(int n, String s, int iterationNo) {
        if (n==1) {
            if (s.charAt(0) == 'a' + iterationNo) {
                return 0;
            } else {
                return 1;
            }
        }
        int noOfLetters = (int)(Math.log(n) / Math.log(2)) + 1;
        int[] firstHalf = new int[noOfLetters];
        int[] secondHalf = new int[noOfLetters];
        int count = 0;
        for (int i=0; i<n/2; i++) {
            int charAsNumber = s.charAt(i) - 'a' - iterationNo;
            if (charAsNumber+1 > noOfLetters || charAsNumber < 0)
                continue;
            else {
                firstHalf[charAsNumber]++;
                count++;
            }
        }
        for (int i=n/2; i<n; i++) {
            int charAsNumber = s.charAt(i) - 'a' - iterationNo;
            if (charAsNumber+1 > noOfLetters || charAsNumber < 0)
                continue;
            else {
                secondHalf[charAsNumber]++;
                count++;
            }
        }
        if (count == 0) return n;
        int i = 0;
        if (firstHalf[i] == secondHalf[i]) {
            int temp1 = n/2 - firstHalf[i] + calculateAnswer(n/2, s.substring(n/2), iterationNo+1);
            int temp2 = n/2 - secondHalf[i] + calculateAnswer(n/2, s.substring(0, n/2), iterationNo+1);
            return Math.min(temp1, temp2);
        } else if (firstHalf[i] > secondHalf[i]) {
            return n/2 - firstHalf[i] + calculateAnswer(n/2, s.substring(n/2), iterationNo+1);
        } else {
            return n/2 - secondHalf[i] + calculateAnswer(n/2, s.substring(0, n/2), iterationNo+1);
        }
    }
}


import java.util.*;
import java.lang.*;

public class Main
{
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        while ( t-- > 0 ) {
            int n = scanner.nextInt();
            String s = scanner.next();
            int iterationNo = 0;
            int ans = 0;
            ans = calculateAnswer(n, s, iterationNo);
            System.out.println(ans);
        }
    }

    private static int calculateAnswer(int n, String s, int iterationNo) {
        if (n==1) {
            if (s.charAt(0) == 'a' + iterationNo) {
                return 0;
            } else {
                return 1;
            }
        }
        int noOfLetters = (int)(Math.log(n) / Math.log(2)) + 1;
        int[] firstHalf = new int[noOfLetters];
        int[] secondHalf = new int[noOfLetters];
        int count = 0;
        for (int i=0; i<n/2; i++) {
            int charAsNumber = s.charAt(i) - 'a' - iterationNo;
            if (charAsNumber+1 > noOfLetters || charAsNumber < 0)
                continue;
            else {
                firstHalf[charAsNumber]++;
                count++;
            }
        }
        for (int i=n/2; i<n; i++) {
            int charAsNumber = s.charAt(i) - 'a' - iterationNo;
            if (charAsNumber+1 > noOfLetters || charAsNumber < 0)
                continue;
            else {
                secondHalf[charAsNumber]++;
                count++;
            }
        }
        if (count == 0) return n;
        int i = 0;
        if (firstHalf[i] == secondHalf[i]) {
            int temp1 = calculateAnswer(n/2, s.substring(n/2), iterationNo+1);
            int temp2 = calculateAnswer(n/2, s.substring(0, n/2), iterationNo+1);
            return Math.min(temp1, temp2) + n/2 - firstHalf[i];
        } else if (firstHalf[i] > secondHalf[i]) {
            return n/2 - firstHalf[i] + calculateAnswer(n/2, s.substring(n/2), iterationNo+1);
        } else {
            return n/2 - secondHalf[i] + calculateAnswer(n/2, s.substring(0, n/2), iterationNo+1);
        }
    }
}


import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int t=Integer.parseInt(br.readLine());
        while(t-->0)
        {
            int n=Integer.parseInt(br.readLine());
            char carr[]=br.readLine().toCharArray();
            int chars=(int)(Math.log(n)/Math.log(2));
            //System.out.println(chars);
            int i=0,j=n-1,moves=0;
            int req=n/2,alp=0;
            int size=n/2;
            while(i<j)
            {
                //System.out.println(i+" "+j);
                int mid=(i+j)/2;
                //if(alp==1)
                //pw.println(i+" "+j+" "+mid);
                int cntr1[]=new int[26];
                int cntr2[]=new int[26];
                //if(alp==1)
                //pw.println(i+" "+mid);
                for(int k=i;k<=mid;k++)
                {
                    //if(alp==1)
                    //pw.println("1a "+carr[k]);
                    cntr1[carr[k]-'a']++;
                    //if(alp==1)
                    //pw.println(k+" "+mid);
                }
                for(int k=mid+1;k<=j;k++)
                {
                    //if(alp==1)
                    //pw.println("1b "+carr[k]);
                    cntr2[carr[k]-'a']++;
                }
                boolean done=true;
                if(cntr1[alp]>cntr2[alp])
                {
                    done=false;
                    moves+=(int)Math.abs((size-cntr1[alp]));
                    i=mid+1;
                    //System.out.println(i+" "+j);
                    size/=2;
                    alp++;
                    continue;
                 //   break;
                }
                if(cntr1[alp]<cntr2[alp])
                {
                    done=false;
                    moves+=(int)Math.abs((size-cntr2[alp]));
                    j=mid;
                    size/=2;
                    alp++;
                    //System.out.println(i+" "+j);
                    continue;
                //    break;
                }
                for(int k=alp+1;k<=chars&&done;k++)
                {
                    if(cntr1[k]>cntr2[k])
                    {
                        done=false;
                        moves+=(int)Math.abs((size-cntr2[alp]));
                        j=mid;
                        break;
                    }
                    else if(cntr1[k]<cntr2[k])
                    {
                        done=false;
                        moves+=(int)Math.abs((size-cntr1[alp]));
                        i=mid+1;
                        break;
                    }
                    //System.out.println(i+" "+j);
                }
                if(done)
                {
                    moves+=(int)Math.abs((size-cntr1[alp]));
                    i=mid+1;

                }
                alp++;
                //System.out.println(moves);
                //pw.println(moves+" "+alp);
                size/=2;
            }
            if(carr[i]!=(char)(alp+97))
                moves++;
            pw.println(moves);
        }
        pw.flush();
        pw.close();
    }
}


import java.util.*;
import java.io.*;
public class Main
{
    public static int dac(char carr[],int c,int l,int r)
    {
        if(l==r)
        {
            if((carr[l]-'a')==c)
            return 0;
            return 1;
        }
        int mid=(l+r)/2;
        int cntr1=0,cntr2=0;
        for(int i=l;i<=mid;i++)
        if((carr[i]-'a')!=c)
        cntr1++;
        for(int i=mid+1;i<=r;i++)
        if((carr[i]-'a')!=c)
        cntr2++;
        c++;
        return Math.min(cntr1+dac(carr,c,mid+1,r),cntr2+dac(carr,c,l,mid));
    }
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int t=Integer.parseInt(br.readLine());
        while(t-->0)
        {
            int n=Integer.parseInt(br.readLine());
            char carr[]=br.readLine().toCharArray();
            pw.println(dac(carr,0,0,n-1));
        }
        pw.flush();
        pw.close();
    }
}


//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    private static int solve(char[] str, int l, int r, char cur)
    {
        if(l==r) return str[l]==cur?0:1;
        int mid=(l+r)/2;

        int c1=0,c2=0;
        for(int i=0;i<=mid;i++) if(str[i]!=cur) c1++;
        for(int i=mid+1;i<=r;i++) if(str[i]!=cur) c2++;

        int tmp1=c1+solve(str,mid+1,r,(char)(cur+1));
        int tmp2=c2+solve(str,l,mid,(char)(cur+1));

        return Math.min(tmp1,tmp2);
    }
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        int T=Integer.parseInt(br.readLine().trim());
        StringBuilder sb=new StringBuilder();

        while(T-->0)
        {
            N=Integer.parseInt(br.readLine().trim());
            char[] str=br.readLine().trim().toCharArray();

            sb.append(solve(str,0,N-1,'a')).append("\n");
        }
        System.out.println(sb);
    }
}


//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    private static int solve(char[] str, int l, int r, char cur)
    {
        if(l==r) return str[l]==cur?0:1;
        int mid=(l+r)/2;

        int c1=0,c2=0;
        for(int i=l;i<=mid;i++) if(str[i]!=cur) c1++;
        for(int i=mid+1;i<=r;i++) if(str[i]!=cur) c2++;

        int tmp1=c1+solve(str,mid+1,r,(char)(cur+1));
        int tmp2=c2+solve(str,l,mid,(char)(cur+1));

        return Math.min(tmp1,tmp2);
    }
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        int T=Integer.parseInt(br.readLine().trim());
        StringBuilder sb=new StringBuilder();

        while(T-->0)
        {
            N=Integer.parseInt(br.readLine().trim());
            char[] str=br.readLine().trim().toCharArray();

            sb.append(solve(str,0,N-1,'a')).append("\n");
        }
        System.out.println(sb);
    }
}


import java.util.Scanner;

public class hello {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            char checker = 'a';
            String s = sc.next();
            int ans = getMin(s, 0, n - 1, checker);
            System.out.println(ans);
        }
    }

    private static int getMin(String s, int l, int r, char checker) {
        if (l == r) {
            if (s.charAt(l) == checker)
                return 0;
            else
                return 1;
        }
        int mid = (l + r) / 2;
        return Math.min(getCost(s, mid + 1, r, checker) + getMin(s, l, mid, (char) ((int) checker + 1)),
                getCost(s, l, mid, checker) + getMin(s, mid + 1, r, (char) ((int) checker + 1)));
    }

    private static int getCost(String s, int l, int r, char c) {
        int cnt = 0;
        for (int i = l; i <= r; i++)
            if (s.charAt(i) != c)
                cnt++;
        return cnt;
    }
}


import java.util.Scanner;

public class hello {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            char checker = 'a';
            String half = sc.next();
            int ans = 0;
            while (half.length() > 1) {
                String half1 = "";
                String half2 = "";
                int c = 0, d = 0;
                for (int i = 0; i < half.length() / 2; i++) {
                    half1 += half.charAt(i);
                    if (half.charAt(i) == checker) {
                        c++;
                    }
                }
                for (int i = half.length() / 2; i < half.length(); i++) {
                    half2 += half.charAt(i);
                    if (half.charAt(i) == checker) {
                        d++;
                    }
                }
                ans += Math.min((half.length() / 2) - c, (half.length() / 2) - d);
                if (c == d)
                    half = half2;
                else if (c > d)
                    half = half2;
                else
                    half = half1;
                checker = (char) ((int) checker + 1);
            }
            if (half.charAt(0) != checker)
                System.out.println(ans + 1);
            else System.out.println(ans);
        }
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class D_Round_656_Div3 {
    public static long MOD = 1000000007;
    static int[][] dp;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int T = in.nextInt();
        for (int z = 0; z < T; z++) {
            int n = in.nextInt();
            String line = in.nextLine();
            int[][] count = new int[26][n];
            for (int i = 0; i < n; i++) {
                int index = line.charAt(i) - 'a';
                count[index][i]++;
                if (i > 0) {
                    for (int j = 0; j < 26; j++) {
                        count[j][i] += count[j][i - 1];
                    }
                }
            }
            int l = Integer.numberOfTrailingZeros(n);
            dp = new int[26][n];

            for (int[] a : dp) {
                Arrays.fill(a, -1);
            }

            //System.out.println(l);
            out.println(cal(0, 0, count));
        }

        out.close();
    }

    static int cal(int index, int need, int[][] count) {
        int l = Integer.numberOfTrailingZeros(count[0].length) - need;
        if (l == 0) {
            int v = count[need][index] - (index > 0 ? count[need][index - 1] : 0);

            return 1 - v;
        }
        if (dp[need][index] != -1) {
            return dp[need][index];
        }
        int len = 1 << l;
        //System.out.println(l + " " + len + " " + need + " " + index);
        int a = count[need][index + (len / 2) - 1] - (index > 0 ? count[need][index - 1] : 0);
        int b = count[need][index + len - 1] - count[need][index + (len / 2) - 1];
        a = len / 2 - a + cal(index + len / 2, need + 1, count);
        b = len / 2 - b + cal(index, need + 1, count);
        return dp[need][index] = Integer.min(a, b);
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }

        long val = pow(a, b / 2);
        if (b % 2 == 0) {
            return val * val;
        } else {
            return val * (val * a);

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class D_Round_656_Div3 {
    public static long MOD = 1000000007;
    static int[][][] dp;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int T = in.nextInt();
        for (int z = 0; z < T; z++) {
            int n = in.nextInt();
            String line = in.nextLine();
            int[][] count = new int[26][n];
            for (int i = 0; i < n; i++) {
                int index = line.charAt(i) - 'a';
                count[index][i]++;
                if (i > 0) {
                    for (int j = 0; j < 26; j++) {
                        count[j][i] += count[j][i - 1];
                    }
                }
            }
            int l = Integer.numberOfTrailingZeros(n);
            dp = new int[l + 1][26][n];
            for (int[][] a : dp) {
                for (int[] b : a) {
                    Arrays.fill(b, -1);
                }
            }
            //System.out.println(l);
            out.println(cal(0, 0, l, count));
        }

        out.close();
    }

    static int cal(int index, int need, int l, int[][] count) {
        if (l == 0) {
            int v = count[need][index] - (index > 0 ? count[need][index - 1] : 0);

            return 1 - v;
        }
        if (dp[l][need][index] != -1) {
            return dp[l][need][index];
        }
        int len = 1 << l;
        //System.out.println(l + " " + len + " " + need + " " + index);
        int a = count[need][index + (len / 2) - 1] - (index > 0 ? count[need][index - 1] : 0);
        int b = count[need][index + len - 1] - count[need][index + (len / 2) - 1];
        a = len / 2 - a + cal(index + len / 2, need + 1, l - 1, count);
        b = len / 2 - b + cal(index, need + 1, l - 1, count);
        return dp[l][need][index] = Integer.min(a, b);
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }

        long val = pow(a, b / 2);
        if (b % 2 == 0) {
            return val * val;
        } else {
            return val * (val * a);

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class A_Good_String
{
	InputReader in;PrintWriter pw;
	char str[];

	long pow(long base,long power)
	{
		if(power==0) return 1L;
		long temp = 1L;
		if(power%2==1)
		{
			temp = base;
		}
		base = (base*base);
		return (temp*pow(base,power/2L));
	}

	long getAns(int l,int r ,char ch)
	{
		int mid = (int)Math.floor((l+r)/(double)2);
		if(r-l+1 == 1)
		{
			if(str[l] == ch) return 0;
			return 1;
		}

		long c1 =0,c2=0;
		for(int i=0;i<=mid;i++)
		{
			if(str[i] != ch)
				c1++;
		}

		for(int i=mid+1;i<=r;i++)
		{
			if(str[i] != ch)
				c2++;
		}

		return Math.min(c1+getAns(mid+1,r,(char)(ch+1)),c2+getAns(l,mid,(char)(ch+1)));
	}
	void solve(int test) throws Exception
	{
		int n = ni();
		str = nln().toCharArray();
		pn(getAns(0,n-1,'a'));
	}
	void run() throws Exception
	{
		in = new InputReader();
		pw = new PrintWriter(System.out);
		int test = ni();
		while(test--!=0){solve(test);}
		pw.close();
	}
	public static void main(String[] args) throws Exception
	{
		new A_Good_String().run();
	}

	void p(Object o){pw.print(o);}
	void pn(Object o){pw.println(o);}
	void pn(){pw.println();}
	void spn(Object o){System.out.println(o);};
	String nln() throws Exception {return in.nextLine();}
	int ni() throws Exception {return Integer.parseInt(in.next());}
	double nd() throws Exception {return Double.parseDouble(in.next());}
	long nl() throws Exception {return Long.parseLong(in.next());}
	class InputReader
	{
		BufferedReader br;
		StringTokenizer st;

		public InputReader()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public InputReader(String s) throws IOException
		{
			br = new BufferedReader(new FileReader(s));
		}

		String next() throws Exception
		{
			if(st==null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					throw new Exception(e.toString());
				}
			}
			return st.nextToken();
		}

		String nextLine() throws Exception
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch(IOException e)
			{
				throw new Exception(e.toString());
			}
			return str;
		}
	}
}


import java.io.*;
import java.util.*;
import java.math.*;

public class A_Good_String
{
	InputReader in;PrintWriter pw;
	char str[];

	long pow(long base,long power)
	{
		if(power==0) return 1L;
		long temp = 1L;
		if(power%2==1)
		{
			temp = base;
		}
		base = (base*base);
		return (temp*pow(base,power/2L));
	}

	long getAns(int l,int r ,char ch)
	{
		//pn(l+" "+r);
		int mid = (int)Math.floor((l+r)/(double)2);
		if(r-l+1 == 1)
		{
			if(str[l] == ch) return 0;
			return 1;
		}

		long c1 =0,c2=0;
		for(int i=l;i<=mid;i++)
		{
			if(str[i] != ch)
				c1++;
		}

		for(int i=mid+1;i<=r;i++)
		{
			if(str[i] != ch)
				c2++;
		}

		return Math.min(c1+getAns(mid+1,r,(char)(ch+1)),c2+getAns(l,mid,(char)(ch+1)));
	}
	void solve(int test) throws Exception
	{
		int n = ni();
		str = nln().toCharArray();
		pn(getAns(0,n-1,'a'));
	}
	void run() throws Exception
	{
		in = new InputReader();
		pw = new PrintWriter(System.out);
		int test = ni();
		while(test--!=0){solve(test);}
		pw.close();
	}
	public static void main(String[] args) throws Exception
	{
		new A_Good_String().run();
	}

	void p(Object o){pw.print(o);}
	void pn(Object o){pw.println(o);}
	void pn(){pw.println();}
	void spn(Object o){System.out.println(o);};
	String nln() throws Exception {return in.nextLine();}
	int ni() throws Exception {return Integer.parseInt(in.next());}
	double nd() throws Exception {return Double.parseDouble(in.next());}
	long nl() throws Exception {return Long.parseLong(in.next());}
	class InputReader
	{
		BufferedReader br;
		StringTokenizer st;

		public InputReader()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public InputReader(String s) throws IOException
		{
			br = new BufferedReader(new FileReader(s));
		}

		String next() throws Exception
		{
			if(st==null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					throw new Exception(e.toString());
				}
			}
			return st.nextToken();
		}

		String nextLine() throws Exception
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch(IOException e)
			{
				throw new Exception(e.toString());
			}
			return str;
		}
	}
}


	// _________________________RATHOD_____________________________________________________________
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class Main
{
    static ArrayList<ArrayList<Integer>> graph;
    static int visited[];
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    static String s;
    public static void main(String[] args)
    {
        FastReader sc=new FastReader();
        int t=sc.nextInt();
        while(t>0)
        {
            t--;
            int n=sc.nextInt();
            s=sc.next();
            char ch='a';
            if(n==1)
            {
                if(s.charAt(0)=='a')
                System.out.println(0);
                else
                System.out.println(1);
            }
            if(n!=1)
            System.out.println(countc(1,n,ch,n));

        }

    }
    public static int countc(int st,int e,char ch,int size)
    {
                int   mid=((e-st+1)/2)+st-1;
                int l=countf(ch,st,mid);
                int r=countf(ch,(mid+1),e);
                int rl=size/2-l;
                int rr=size/2-r;
                if(size==2)
                {
                   if(s.charAt(st-1)==ch)
                   {
                     if(s.charAt(e-1)==(ch+1))
                     {
                       return 0;
                     }
                     else
                     return 1;
                   }
                   else
                   {
                      if(s.charAt(st-1)==ch+1)
                     {
                     if(s.charAt(e-1)==(ch))
                     {
                       return 0;
                     }
                     else
                     return 1;
                     }
                     else
                     {
                       if(s.charAt(e-1)==(ch))
                     {
                       return 1;
                     }
                     else
                     return 2;
                     }

                   }
                }
                else
                {

                    int lll=(countc(st,mid,((char) (ch+1)),size/2)+rr);
                    int rrr=(countc(mid+1,e,((char) (ch+1)),size/2)+rl);
                   // System.out.println(lll+" "+rrr);
                    return((int) Math.min(lll,rrr));
                }
    }
    public static int countf(char ch,int st,int e)
    {
        int i;
        int count=0;
        for(i=st-1;i<=e-1;i++)
        {
            if(s.charAt(i)==ch)
            count++;
        }
        return count;
    }
}


	// _________________________RATHOD_____________________________________________________________
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class Main
{
    static ArrayList<ArrayList<Integer>> graph;
    static int visited[];
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    static String s;
    public static void main(String[] args)
    {
        FastReader sc=new FastReader();
        int t=sc.nextInt();
        while(t>0)
        {
            t--;
            int n=sc.nextInt();
            s=sc.next();
            char ch='a';
            if(n==1)
            {
                if(s.charAt(0)=='a')
                System.out.println(0);
                else
                System.out.println(1);
            }
            if(n!=1)
            System.out.println(countc(1,n,ch,n));

        }

    }
    public static int countc(int st,int e,char ch,int size)
    {
                int   mid=((e-st+1)/2)+st-1;
                int l=countf(ch,st,mid);
                int r=countf(ch,(mid+1),e);
                int rl=size/2-l;
                int rr=size/2-r;
                if(size==2)
                {
                   if(s.charAt(st-1)==ch)
                   {
                     if(s.charAt(e-1)==(ch+1))
                     {
                       return 0;
                     }
                     else
                     return 1;
                   }
                   else
                   {
                      if(s.charAt(st-1)==ch+1)
                     {
                     if(s.charAt(e-1)==(ch))
                     {
                       return 0;
                     }
                     else
                     return 1;
                     }
                     else
                     {
                       if((s.charAt(e-1)==(ch))||(s.charAt(e-1)==(ch+1)))
                     {
                       return 1;
                     }
                     else
                     return 2;
                     }

                   }
                }
                else
                {

                    int lll=(countc(st,mid,((char) (ch+1)),size/2)+rr);
                    int rrr=(countc(mid+1,e,((char) (ch+1)),size/2)+rl);
                   // System.out.println(lll+" "+rrr);
                    return((int) Math.min(lll,rrr));
                }
    }
    public static int countf(char ch,int st,int e)
    {
        int i;
        int count=0;
        for(i=st-1;i<=e-1;i++)
        {
            if(s.charAt(i)==ch)
            count++;
        }
        return count;
    }
}


import java.util.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class temp {

	int dp[][][];
	boolean u[][][];
	public int find(int c,int l,int r,String s,int f[][])
	{
		if(l==r)
		{
			if(s.charAt(l)!=(char)(c+97))
				return 1;
			return 0;
		}

		if(u[l][r][c])
			return dp[l][r][c];

		int mid = (l+r)/2;
		int ans = Integer.MAX_VALUE;
		int left = (mid-l+1) - (f[mid][c] - ((l-1)>=0 ? f[l-1][c] : 0));
		int right = (r-mid) - (f[r][c] - f[mid][c]);
		ans = Math.min(left + find(c+1,mid+1,r,s,f) , right + find(c+1,l,mid,s,f));
		u[l][r][c] = true;
		dp[l][r][c] = ans;
		return ans;
	}

	void solve() throws IOException
	{
		FastReader sc=new FastReader();
		int t = sc.nextInt();
		while(t-->0)
		{
			int n = sc.nextInt();
			String s = sc.next();
			int f[][] = new int[n][26];
			for(int i=0;i<n;i++)
			{
				if(i!=0)
				{
					for(int j=0;j<26;j++)
						f[i][j]+=f[i-1][j];
				}
				f[i][s.charAt(i)%97]++;
			}

			u = new boolean[n][n][26];
			dp = new int[n][n][26];
			System.out.println(find(0,0,n-1,s,f));
		}
	}

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		new temp().solve();
	}
	class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.util.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class temp {

	public int find(int c,int l,int r,String s,int f[][])
	{
		if(l==r)
		{
			if(s.charAt(l)!=(char)(c+97))
				return 1;
			return 0;
		}

		int mid = (l+r)/2;
		int ans = Integer.MAX_VALUE;
		int left = (mid-l+1) - (f[mid][c] - ((l-1)>=0 ? f[l-1][c] : 0));
		int right = (r-mid) - (f[r][c] - f[mid][c]);
		ans = Math.min(left + find(c+1,mid+1,r,s,f) , right + find(c+1,l,mid,s,f));
		return ans;
	}

	void solve() throws IOException
	{
		FastReader sc=new FastReader();
		int t = sc.nextInt();
		while(t-->0)
		{
			int n = sc.nextInt();
			String s = sc.next();
			int f[][] = new int[n][26];
			for(int i=0;i<n;i++)
			{
				if(i!=0)
				{
					for(int j=0;j<26;j++)
						f[i][j]+=f[i-1][j];
				}
				f[i][s.charAt(i)%97]++;
			}

			System.out.println(find(0,0,n-1,s,f));
		}
	}

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		new temp().solve();
	}
	class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.util.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class temp {

	HashMap<String,Integer> dp;
	public int find(int c,int l,int r,String s,int f[][])
	{
		if(l==r)
		{
			if(s.charAt(l)!=(char)(c+97))
				return 1;
			return 0;
		}

		String tmp = l+"#"+r+"#"+c;
		if(dp.containsKey(tmp))
			return dp.get(tmp);

		int mid = (l+r)/2;
		int ans = Integer.MAX_VALUE;
		int left = (mid-l+1) - (f[mid][c] - ((l-1)>=0 ? f[l-1][c] : 0));
		int right = (r-mid) - (f[r][c] - f[mid][c]);
		ans = Math.min(left + find(c+1,mid+1,r,s,f) , right + find(c+1,l,mid,s,f));
		dp.put(tmp , ans);
		return ans;
	}

	void solve() throws IOException
	{
		FastReader sc=new FastReader();
		int t = sc.nextInt();
		while(t-->0)
		{
			int n = sc.nextInt();
			String s = sc.next();
			int f[][] = new int[n][26];
			for(int i=0;i<n;i++)
			{
				if(i!=0)
				{
					for(int j=0;j<26;j++)
						f[i][j]+=f[i-1][j];
				}
				f[i][s.charAt(i)%97]++;
			}

			dp = new HashMap<>();
			System.out.println(find(0,0,n-1,s,f));
		}
	}

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		new temp().solve();
	}
	class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.*;
import java.util.*;

public class Main{
    static CustomScanner input;
    static PrintWriter out;

    public static void main(String commandLineArgument[]){
        input = new CustomScanner();
        out = new PrintWriter(System.out);
        int tc = input.nextInt();
        while(tc --> 0) {
            int n = input.nextInt();
            String s = input.next();
            int [][] characterCount = new int[n + 1][26];
            for(int i = 0; i < n; ++i){
                int reqChar = s.charAt(i) - 'a';
                for(int j = 0; j < 26; ++j){
                    characterCount[i + 1][j] = characterCount[i][j] + ((j == reqChar) ? 1 : 0);
                }
            }

            int answer = findGoodArray(1 , n , 0, characterCount);
            out.println(answer);
        }
        out.close();
    }

    private static int findGoodArray(int l, int r , int reqChar , int [][] characterCount) {
        if(l == r){
            int reqCount = characterCount[r][reqChar] - characterCount[r - 1][reqChar];
            return (reqCount == 0) ? 1 : 0;
        }
        int mid = l + (r - l)/2;

        int halfCount = ((r - l) + 1)/2;

        int firstHalf = characterCount[mid][reqChar] - characterCount[l - 1][reqChar];
        int reqFirstHalf = halfCount - firstHalf;

        int minReq = reqFirstHalf + findGoodArray(mid + 1 , r , reqChar + 1 , characterCount);

        int secondHalf = characterCount[r][reqChar] - characterCount[mid][reqChar];
        int reqSecondHalf = halfCount - secondHalf;

        minReq = Math.min(minReq , reqSecondHalf + findGoodArray(l , mid , reqChar + 1 , characterCount));

        return minReq;
    }

}
class CustomScanner{
    BufferedReader br;
    StringTokenizer st;
    public CustomScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    String next() {
        while(st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch(Exception e) { throw null;}
        }
        return st.nextToken();
    }
    int nextInt() { return Integer.parseInt(next());}
    double nextDouble() { return Double.parseDouble(next());}
    long nextLong() { return Long.parseLong(next());}
}


import java.io.*;
import java.util.*;

public class Main{
    static CustomScanner input;
    static PrintWriter out;

    public static void main(String commandLineArgument[]){
        input = new CustomScanner();
        out = new PrintWriter(System.out);
        int tc = input.nextInt();
        while(tc --> 0) {
            int n = input.nextInt();
            String s = input.next();
            int [][] characterCount = new int[n + 1][26];
            for(int i = 0; i < n; ++i){
                int reqChar = s.charAt(i) - 'a';
                for(int j = 0; j < 26; ++j){
                    characterCount[i + 1][j] = characterCount[i][j] + ((j == reqChar) ? 1 : 0);
                }
            }

            int answer = findGoodArray(1 , n , 0, characterCount);
            out.println(answer);
        }
        out.close();
    }

    private static int findGoodArray(int l, int r , int reqChar , int [][] characterCount) {
        if(l == r){
            int reqCount = characterCount[r][reqChar] - characterCount[r - 1][reqChar];
            return (reqCount == 0) ? 1 : 0;
        }

        int mid = l + (r - l)/2;
        int halfCount = ((r - l) + 1)/2;

        int firstHalf = characterCount[mid][reqChar] - characterCount[l - 1][reqChar];
        int reqFirstHalf = halfCount - firstHalf;
        int minReq = reqFirstHalf + findGoodArray(mid + 1 , r , reqChar + 1 , characterCount);

        int secondHalf = characterCount[r][reqChar] - characterCount[mid][reqChar];
        int reqSecondHalf = halfCount - secondHalf;
        minReq = Math.min(minReq , reqSecondHalf + findGoodArray(l , mid , reqChar + 1 , characterCount));

        return minReq;
    }

}
class CustomScanner{
    BufferedReader br;
    StringTokenizer st;
    public CustomScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    String next() {
        while(st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch(Exception e) { throw null;}
        }
        return st.nextToken();
    }
    int nextInt() { return Integer.parseInt(next());}
    double nextDouble() { return Double.parseDouble(next());}
    long nextLong() { return Long.parseLong(next());}
}


import java.util.*;
public class Main {
  static	int c=0;
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int t=in.nextInt();
		while(t-->0) {
			int n=in.nextInt();
			String str=in.next();
			int z=good(str, 0, str.length()-1, 'a');
			System.out.println(z);

		}

	}

	public static int good(String str, int l ,int r, char ch){
	    c++;
	    if(l==r){
	        if(str.charAt(l)==ch){

	            return 0;
	        }
	        return 1;
	    }
	    if(l>r){
	        return 1000000;
	    }
	    int mid=(l+r)/2;
	    int c1=0, c2=0;
	    for(int i=l ; i<=mid ; i++){
	        if(str.charAt(i)!=ch){
	            c1+=1;

	        }
	    }
	    for(int i=mid+1 ; i<=r ; i++){
	        if(str.charAt(i)!=ch){
	            c2+=1;

	        }
	    }
	    c1+=good(str, mid+1, r, (char)(ch+1));
	    c2+=good(str, l, mid, (char)(ch+1));
	    return Math.min(c1, c2);
	}

}


import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in= new Scanner(System.in);
		int t=in.nextInt();
		while(t-->0){
			int n=in.nextInt();
			String s=in.next();

			int m=1+(int)(Math.log(n)/Math.log(2));
			int count=0;
			int t1=0;
			int t2=0;
			int k=0;
			int j=0;
			while(n>=1){
				for(int i=j;i<j+n/2;i++){
					if(s.charAt(i)==(char)(97+k))
					t1++;
				}
				for(int i=n/2+j;i<n+j;i++){
					if(s.charAt(i)==(char)(97+k))
					t2++;
				}

				if(t1>=t2){
				count+=(n/2-t1);
				j=n/2;
				}
				else{
				count+=(n/2-t2);
				j=0;
				}

				n=n/2;
				k++;
				t1=0;
				t2=0;
			}

			if(count>=1)
			System.out.println(count-1);
			else
			System.out.println(0);
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = in.nextInt();
            while (T-- > 0)
            {
                solve(in, out);
            }
        }

        private void solve(Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            String S = in.next();
            out.println(recurr(0, N - 1, 'a', S));
        }

        private int recurr(int start, int end, char a, String S)
        {
            if (start == end) return S.charAt(start) == a ? 0 : 1;

            int first = 0, second = 0;
            int mid = start + ((end - start) / 2);
            for (int i = start; i <= mid; i++)
            {
                if (S.charAt(i) == a) continue;
                first++;
            }
            for (int i = mid + 1; i <= end; i++)
            {
                if (S.charAt(i) == a) continue;
                second++;
            }
        /*if (first < second){
            return first + recurr(mid + 1, end, (char) (a + 1), S);
        }else if (first > second) {
            return second + recurr(start, mid, (char) (a + 1), S);
        } else {
            return Math.min(first + recurr(mid + 1, end, (char) (a + 1), S), second + recurr(start, mid, (char) (a + 1), S));
        }*/
            return Math.min(first + recurr(mid + 1, end, (char) (a + 1), S), second + recurr(start, mid, (char) (a + 1), S));
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = in.nextInt();
            while (T-- > 0)
            {
                solve(in, out);
            }
        }

        private void solve(Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            String S = in.next();
            out.println(recurr(0, N - 1, 'a', S));
        }

        private int recurr(int start, int end, char a, String S)
        {
            if (start == end) return S.charAt(start) == a ? 0 : 1;

            int first = 0, second = 0;
            int mid = start + ((end - start) / 2);
            for (int i = start; i <= mid; i++)
            {
                if (S.charAt(i) == a) continue;
                first++;
            }
            for (int i = mid + 1; i <= end; i++)
            {
                if (S.charAt(i) == a) continue;
                second++;
            }
            if (first < second)
            {
                return first + recurr(mid + 1, end, (char) (a + 1), S);
            } else if (first > second)
            {
                return second + recurr(start, mid, (char) (a + 1), S);
            } else
            {
                return Math.min(first + recurr(mid + 1, end, (char) (a + 1), S), second + recurr(start, mid, (char) (a + 1), S));
            }
        }

    }
}


// coded by Krishna Sundar //

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

public class Main {

    private int calc(int[][] count, int start, int end, int C) {
        return count[end][C]-(start-1<0?0:count[start-1][C]);
    }

    private int GO(String str, int[][] count, int start, int end, int C) {
        if (start==end) {
            if ((str.charAt(start)-'a')!=C) {
                return 1;
            }
            return 0;
        }
        int mid = (start+end)/2;
        int left = calc(count, start, mid, C);
        int right = calc(count, mid+1, end, C);
        int len = mid-start+1;
        int res1 = 0;
        res1 += (len-left) + GO(str, count, mid+1, end, C+1);
        int res2 = 0;
        len = (end-(mid+1))+1;
        res2 += (len-right) + GO(str, count, start, mid, C+1);
        return Math.min(res1, res2);
    }

    public void solve(Read input, Write output) throws Exception {
        int cases = input.readInt();
        while (cases-->0) {
            int N = input.readInt();
            int[][] count = new int[N+1][26];
            String str = input.readString();
            for (int i=0;i<N;i++) {
                int pos = str.charAt(i)-'a';
                for (int j=0;j<26;j++) {
                    count[i][j] = ((pos==j)?1:0)+((i-1)<0?0:count[i-1][j]);
                }
            }
            output.printLine(GO(str, count, 0, N-1, 0));
        }
    }

    public static void main(String[] args) throws Exception {
        Read input = new Read();
        Write output = new Write();
        Main D = new Main();
        D.solve(input, output);
        output.flush();
        output.close();
    }

    // java fast io reader and writer
    // taken from various sources and customized

    static class Read {

        private byte[] buffer =new byte[10*1024];
        private int index;
        private InputStream input_stream;
        private int total;

        public Read() {
            input_stream = System.in;
        }

        public int read()throws IOException {
            if(total<0)
                throw new InputMismatchException();
            if(index>=total) {
                index=0;
                total= input_stream.read(buffer);
                if(total<=0)
                    return -1;
            }
            return buffer[index++];
        }

        public long readLong() throws IOException {
            long number=0;
            int n= read();
            while(isWhiteSpace(n))
                n= read();
            long neg=1l;
            if(n=='-') {
                neg=-1l;
                n= read();
            }
            while(!isWhiteSpace(n)) {
                if(n>='0'&&n<='9') {
                    number*=10l;
                    number+=(long)(n-'0');
                    n= read();
                }
                else throw new InputMismatchException();
            }
            return neg*number;
        }

        public int readInt() throws IOException {
            int integer=0;
            int n= read();
            while(isWhiteSpace(n))
                n= read();
            int neg=1;
            if(n=='-') {
                neg=-1;
                n= read();
            }
            while(!isWhiteSpace(n)) {
                if(n>='0'&&n<='9') {
                    integer*=10;
                    integer+=n-'0';
                    n= read();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }

        public double readDouble()throws IOException {
            double doub=0;
            int n= read();
            while(isWhiteSpace(n))
                n= read();
            int neg=1;
            if(n=='-') {
                neg=-1;
                n= read();
            }
            while(!isWhiteSpace(n)&&n!='.') {
                if(n>='0'&&n<='9') {
                    doub*=10;
                    doub+=n-'0';
                    n= read();
                }
                else throw new InputMismatchException();
            }

            if(n=='.') {
                n= read();
                double temp=1;
                while(!isWhiteSpace(n)) {
                    if(n>='0'&&n<='9') {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n= read();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }

        public String readString()throws IOException {
            StringBuilder sb = new StringBuilder();
            int n = read();
            while (isWhiteSpace(n))
                n = read();
            while (!isWhiteSpace(n)) {
                sb.append((char)n);
                n = read();
            }
            return sb.toString();
        }

        private boolean isWhiteSpace(int n) {
            if(n==' '|| n=='\n'|| n=='\r'|| n=='\t'|| n==-1)
                return true;
            return false;
        }
    }

    static class Write {

        private final BufferedWriter bw;

        public Write() {
            bw = new BufferedWriter(new OutputStreamWriter(System.out));
        }
        public void print(Object str) throws IOException {
            bw.append(str+"");
        }
        public void printLine(Object str) throws IOException {
            print(str);
            bw.append("\n");
        }
        public void close()throws IOException {
            bw.close();
        }
        public void flush()throws IOException {
            bw.flush();
        }
    }
}


// coded by Krishna Sundar //

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

public class Main {

    private int calc(int[][] count, int start, int end, int C) {
        return count[end][C]-(start-1<0?0:count[start-1][C]);
    }

    public void solve(Read input, Write output) throws Exception {
        int cases = input.readInt();
        while (cases-->0) {
            int N = input.readInt();
            int[][] count = new int[N+1][26];
            String str = input.readString();
            for (int i=0;i<N;i++) {
                int pos = str.charAt(i)-'a';
                for (int j=0;j<26;j++) {
                    count[i][j] = ((pos==j)?1:0)+((i-1)<0?0:count[i-1][j]);
                }
            }
            int start = 0;
            int end = N-1;
            int C = 0;
            int res = 0;
            while (start<=end) {
                if (start==end) {
                    if ((str.charAt(start)-'a')!=C) {
                        res++;
                    }
                    break;
                }
                int mid = (start+end)/2;
                int left = calc(count, start, mid, C);
                int right = calc(count, mid+1, end, C);
                if (left>=right) {
                    int len = mid-start+1;
                    res += (len-left);
                    start = mid+1;
                } else {
                    int len = (end-(mid+1))+1;
                    res += (len-right);
                    end = mid;
                }
                C++;
            }
            output.printLine(res);
        }
    }

    public static void main(String[] args) throws Exception {
        Read input = new Read();
        Write output = new Write();
        Main D = new Main();
        D.solve(input, output);
        output.flush();
        output.close();
    }

    // java fast io reader and writer
    // taken from various sources and customized

    static class Read {

        private byte[] buffer =new byte[10*1024];
        private int index;
        private InputStream input_stream;
        private int total;

        public Read() {
            input_stream = System.in;
        }

        public int read()throws IOException {
            if(total<0)
                throw new InputMismatchException();
            if(index>=total) {
                index=0;
                total= input_stream.read(buffer);
                if(total<=0)
                    return -1;
            }
            return buffer[index++];
        }

        public long readLong() throws IOException {
            long number=0;
            int n= read();
            while(isWhiteSpace(n))
                n= read();
            long neg=1l;
            if(n=='-') {
                neg=-1l;
                n= read();
            }
            while(!isWhiteSpace(n)) {
                if(n>='0'&&n<='9') {
                    number*=10l;
                    number+=(long)(n-'0');
                    n= read();
                }
                else throw new InputMismatchException();
            }
            return neg*number;
        }

        public int readInt() throws IOException {
            int integer=0;
            int n= read();
            while(isWhiteSpace(n))
                n= read();
            int neg=1;
            if(n=='-') {
                neg=-1;
                n= read();
            }
            while(!isWhiteSpace(n)) {
                if(n>='0'&&n<='9') {
                    integer*=10;
                    integer+=n-'0';
                    n= read();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }

        public double readDouble()throws IOException {
            double doub=0;
            int n= read();
            while(isWhiteSpace(n))
                n= read();
            int neg=1;
            if(n=='-') {
                neg=-1;
                n= read();
            }
            while(!isWhiteSpace(n)&&n!='.') {
                if(n>='0'&&n<='9') {
                    doub*=10;
                    doub+=n-'0';
                    n= read();
                }
                else throw new InputMismatchException();
            }

            if(n=='.') {
                n= read();
                double temp=1;
                while(!isWhiteSpace(n)) {
                    if(n>='0'&&n<='9') {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n= read();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }

        public String readString()throws IOException {
            StringBuilder sb = new StringBuilder();
            int n = read();
            while (isWhiteSpace(n))
                n = read();
            while (!isWhiteSpace(n)) {
                sb.append((char)n);
                n = read();
            }
            return sb.toString();
        }

        private boolean isWhiteSpace(int n) {
            if(n==' '|| n=='\n'|| n=='\r'|| n=='\t'|| n==-1)
                return true;
            return false;
        }
    }

    static class Write {

        private final BufferedWriter bw;

        public Write() {
            bw = new BufferedWriter(new OutputStreamWriter(System.out));
        }
        public void print(Object str) throws IOException {
            bw.append(str+"");
        }
        public void printLine(Object str) throws IOException {
            print(str);
            bw.append("\n");
        }
        public void close()throws IOException {
            bw.close();
        }
        public void flush()throws IOException {
            bw.flush();
        }
    }
}


import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Code {

    public static void main(String[] args) throws IOException
    {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        StringBuilder res = new StringBuilder();
        int t = sc.nextInt();
        while (t-- > 0) {
        	int len = sc.nextInt();
        	String s = sc.next();
        	int result = halve(s, 'a');
        	pw.println(result);
        }
        pw.close();
	}
    public static int halve(String str, char c)
    {
    	int count = 0;
    	if (str.length() == 1)
    	{
    		if (str.charAt(0) == c)
    		{
    			return 0;
    		}
    		else
    		{
    			return 1;
    		}
    	}
    	int half1 = 0;
    	int next1 = 0;
    	int len = str.length()/2;
    	for (int i = 0; i <  len; i++)
    	{
    		if (str.charAt(i) == c)
    		{
    			half1++;
    		}
    		else if (str.charAt(i) == (char)(c +1) || str.charAt(i) == (char)(c + 2))
    		{
    			next1++;
    		}
    	}
    	int half2 = 0;
    	int next2 = 0;
    	for (int i = len; i < str.length(); i++)
    	{
    		if (str.charAt(i) == c)
    		{
    			half2++;
    		}
    		else if (str.charAt(i) == (char)(c +1) || str.charAt(i) == (char)(c + 2))
    		{
    			next2++;
    		}
    	}
    	if (half1 > half2)
    	{
    		count += (len - half1);
    		count += halve(str.substring(len), (char)(c +1));
    	}
    	else if (half2 > half1)
    	{
    		count += (len - half2);
    		count += halve(str.substring(0, len), (char)(c +1 ));
    	}
    	else
    	{
    		count += (str.length()/2 - half1);
    		if (next1 > next2)
    		{
    			count += halve(str.substring(0, len), (char)(c + 1));
    		}
    		else
    		{
    			count += halve(str.substring(len), (char)(c + 1));
    		}
    	}
    	return count;

    }

}


import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Code {

    public static void main(String[] args) throws IOException
    {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        StringBuilder res = new StringBuilder();
        int t = sc.nextInt();
        while (t-- > 0) {
        	int len = sc.nextInt();
        	String s = sc.next();
        	int result = halve(s, 'a');
        	pw.println(result);
        }
        pw.close();
	}
    public static int halve(String str, char c)
    {
    	int count1 = 0;
    	int count2 = 0;
    	if (str.length() == 1)
    	{
    		if (str.charAt(0) == c)
    		{
    			return 0;
    		}
    		else
    		{
    			return 1;
    		}
    	}
    	int half1 = 0;
    	int len = str.length()/2;
    	for (int i = 0; i <  len; i++)
    	{
    		if (str.charAt(i) == c)
    		{
    			half1++;
    		}

    	}
    	int half2 = 0;
    	for (int i = len; i < str.length(); i++)
    	{
    		if (str.charAt(i) == c)
    		{
    			half2++;
    		}
    	}

    	count1 += (len - half1);
    	count1 += halve(str.substring(len), (char)(c +1));

    	count2 += (len - half2);
    	count2 += halve(str.substring(0, len), (char)(c +1 ));

    	return Math.min(count1, count2);

    }

}