import java.util.*;
import java.io.*;
 
public class Main {
	
	public static void main(String[] args) throws IOException,InterruptedException{
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0) {
			int n=sc.nextInt();
			char[] arr=sc.next().toCharArray();
			char[] tmp=arr.clone();
			solve(tmp,n);
			int p=0;
			for (int i = 0; i < tmp.length; i++) {
				if (arr[i]!=tmp[i]) {
					p++;
				}
			}
			pw.println(p);
//			pw.println(c);
		}
		pw.close();
    }
	static void solve(char[] arr,int n) {
		char chr='a';
		int start=0,end=n;
		while (start<=end) {
			int mid=(start+end)/2;
//			pw.print(mid+" ");
			int[] co1=new int[26];
			int[] co2=new int[26];
			for (int i = start; i < mid; i++) {
				co1[arr[i]-'a']++;
			}
			for (int i = mid; i < end; i++) {
				co2[arr[i]-'a']++;
			}
			boolean f=true;
			if (mid==end) {
				f=true;
			}else if (start==mid) {
				f=false;
			}else {
				if (co1[chr-'a']<co2[chr-'a']) {
					f=false;
				}else if(co1[chr-'a']==co2[chr-'a']) {
					for (int i = chr-'a'+1; i < 26; i++) {
						if (co2[i]<co1[i]) {
							f=false;
							break;
						}else if (co2[i]>co1[i]) {
							break;
						}
					}
				}
			}
//			pw.println(Arrays.toString(co1)+" "+Arrays.toString(co2)+" "+c+" "+Arrays.toString(arr));
			if (f) {
				for (int i = start; i < mid; i++) {
					if (arr[i]!=chr) {
						arr[i]=chr;
					}
				}
				start=mid;
			}else {
				for (int i = mid; i < end; i++) {
					if (arr[i]!=chr) {
						arr[i]=chr;
					}
				}
				end=mid;
			}
			chr++;
			if (chr-'a'-1==Math.log(n)/Math.log(2)) break;
//			if (start==end) break;
		}
//		pw.println(arr);
	}
	static PrintWriter pw=new PrintWriter(System.out);
	static class pair implements Comparable<pair> {
		int x;
		int y;
 
		public pair(int x, int y) {
			this.x = x;
			this.y = y;
		}
 
		public String toString() {
			return x + " " + y;
		}
		public boolean equals(Object o) {
            if (o instanceof pair) {
                pair p = (pair)o;
                return p.x == x && p.y == y;
            }
            return false;
        }
        public int hashCode() {
            return new Double(x).hashCode() * 31 + new Double(y).hashCode();
        }
        public int compareTo(pair other) {
        	if(this.x==other.x) {
        		return Long.compare(this.y, other.y);
        	}
			return Long.compare(this.x, other.x);
		}
	}
	static class tuble implements Comparable<tuble> {
		int x;
		int y;
		int z;
 
		public tuble(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}
 
		public String toString() {
			return x + " " + y + " " + z;
		}
 
		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if(this.y==other.y) return this.z - other.z;
				else return this.y - other.y;
			} else {
				return this.x - other.x;
			}
		}
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
	}
}
