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

public class Main implements Runnable {

	class Pair implements Comparable<Pair>{
		public int node;
		public int count;
		Pair(int nd, int c){
			node=nd; count=c;
		}
		public int compareTo(Pair that) {
	        return that.count -  this.count;
	    }
	}
	
	int getMin(int a[], int start, int end, int val){
		if(start==end){
			if(a[start]==val)
				return 0;
			else
				return 1;
		}
		int mid= (start+end)/2;
		
		int count1=0;
		for(int i=start;i<=mid;i++){
			if(a[i]!=val)
				count1++;
		}
		int m1= count1+getMin(a,mid+1,end,val+1);
		
		int count2=0;
		for(int i=mid+1;i<=end;i++){
			if(a[i]!=val)
				count2++;
		}
		int m2= count2+getMin(a,start,mid,val+1);
		
		return Math.min(m1, m2);
	}
	public void solve() throws Exception {

		int t=iread();
		for(int cases=1;cases<=t;cases++){
			int n= iread();
			String s= readword();
			int a[]= new int[n+1];
			for(int i=0;i<n;i++)
				a[i]= (int)s.charAt(i);
			
			int result= getMin(a,0,n-1,(int)'a');
			System.out.println(result);
		}
	}




	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));
			// in = new BufferedReader(new FileReader(filename+".in"));
			// out = new BufferedWriter(new FileWriter(filename+".out"));
			solve();
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public int iread() throws Exception {
		return Integer.parseInt(readword());
	}

	public double dread() throws Exception {
		return Double.parseDouble(readword());
	}

	public long lread() throws Exception {
		return Long.parseLong(readword());
	}

	BufferedReader in;

	BufferedWriter out;

	public String readword() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) {

		try {
			Locale.setDefault(Locale.US);
		} catch (Exception e) {

		}
		// new Thread(new Main()).start();
		new Thread(null, new Main(), "1", 1 << 25).start();
	}
}

