import java.util.*;
import java.io.*;
import java.io.BufferedReader;
import java.awt.Point;

public class Z_D{
	public static long mod= 1000000007;
	public static Debug db;

	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Autocompletion solver = new Autocompletion();
		db=new Debug(System.getSecurityManager()==null);
		solver.solve(1, in, out);
		out.close();
	}
	static class Autocompletion {
		static int freq[][];
		static int n;
		static String s;
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int t1=in.nextInt();
			for(int z1=0;z1<t1;z1++) {
				n=in.nextInt();
				s=in.next();
				freq=new int[n][26];
				for(int i=0;i<n;i++) {
					freq[i][s.charAt(i)-'a']++;
					for(int j=0;j<26;j++) {
						if(i!=0) {
							freq[i][j]+=freq[i-1][j];
						}
					}
				}
				out.println(ans(0,n-1, 0));
			}
		}
		private int ans(int i, int j, int k) {
			int dist=j-i+1;
			char tmp=(char)('a'+k);
			if(i==j) {
				if(s.charAt(i)==tmp) {
					return 0;
				}
				return 1;
			}
			int mid=i+dist/2;
			int tmp2=dist/2;
			if(i==0)return Math.min(tmp2-freq[mid-1][k]+ans(mid,j,k+1), tmp2-(freq[j][k]-freq[mid-1][k])+ans(i,mid-1,k+1));
			return Math.min(tmp2-(freq[mid-1][k]-freq[i-1][k])+ans(mid,j,k+1),tmp2-(freq[j][k]-freq[mid-1][k])+ans(i,mid-1,k+1));
		}
	}
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		Pair(int a, int b){
			x=a;
			y=b;
		}
		@Override
		public int compareTo(Pair arg0) {
			if(arg0.x!=x)return x-arg0.x;
			return y-arg0.y;
		}
	}
	static class Triple implements Comparable<Triple>{
		int x;
		int y;
		int z;
		Triple(int a, int b, int c){
			x=a;
			y=b;
			z=c;
		}
		@Override
		public int compareTo(Triple arg0) {
			if(arg0.x!=x)return x-arg0.x;
			return y-arg0.y;
		}
	}

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
 
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
 
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
 
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public int[] nextIntArr(int n) {
        	int arr[]=new int[n];
        	for(int i=0;i<n;i++) {
        		arr[i]=this.nextInt();
        	}
        	return arr;
        }
    }
	public static class Debug {
        private boolean allowDebug;
 
        public Debug(boolean allowDebug) {
            this.allowDebug = allowDebug;
        }
 
        private void outputName(String name) {
            System.out.print(name + " = ");
        }
 
        public void debug(String name, int x) {
            if (!allowDebug) {
                return;
            }
 
            outputName(name);
            System.out.println("" + x);
        }
 
        public void debug(String name, long x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }
 
        public void debug(String name, double x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }
 
        public void debug(String name, int[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }
 
        public void debug(String name, long[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }
 
        public void debug(String name, double[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }
        
        public void debug(String name, Pair[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            StringBuilder sb = new StringBuilder("[");
            int cnt=0;
            for(Pair y:x) {
            	sb.append("("+y.x+","+y.y+')');
            	if (cnt != x.length-1)sb.append(", ");
            	cnt++;
            }
            System.out.println(sb.append("]").toString());
        }
 
        public void debug(String name, Object x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }
 
        public void debug(String name, Object... x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.deepToString(x));
        }
    }
}
