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

public class Solution
{
    static class Reader {
		BufferedReader br;
		StringTokenizer st;
 
		public Reader() {
			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 class Ele implements Comparable<Ele> 
    {  
        public int x,y;  
        Ele(int x,int y) 
        {  
            this.x=x;this.y=y; 
        }  
        public int compareTo(Ele ob) {  
        if(ob.x!=x)return x-ob.x;
        return this.y-ob.y;  
        }   
    }
    int a1[][];
    long gcd(long a,long b)
    {
        long min=Math.min(a,b);
        long max=Math.max(a,b);
        while (max%min!=0)
        {
            a=max%min;
            max=min;min=a;
        }
        return min;
    }
    int bit(int i,int j,int c)
    {
        if (i+1==j) return 1-(a1[j][c]-a1[i][c]);
        else 
        {
            int m=(i+j)/2;
            int k1=bit(i,m,c+1);
            int k2=bit(m,j,c+1);
            //System.out.println(i+" "+j+" "+k1+" "+k2);
            //if (k1>k2)
            return Math.min( (k2+(m-i)-(a1[m][c]-a1[i][c]))
            , (k1+(m-i)-(a1[j][c]-a1[m][c])));
            //else return k1+(m-i)-Math.max(a1[j][c]-a1[m][c],a1[m][c]-a1[i][c]);
            //if (k1>k2) return (j-m)-(a1[j][c]-a1[m][c])+bit(i,m,c+1);
            //else if (k2>k1)return (m-i)-(a1[m][c]-a1[i][c])+bit(m,j,c+1);
            //else return (m-i)-k1 + Math.min(bit(i,m,c+1),bit (m,j,c+1));
            //System.out.println(i++j++);
        }
    }
	public static void main(String[] args) throws IOException 
	{
		Reader sc=new Reader();Solution G=new Solution();
		PrintWriter o = new PrintWriter(System.out);
		//int t=1;
		int t=sc.nextInt();
		
		int n,m,y,s1,s2;int a[],b[];long k,x;
		boolean b1,b2;String s;
		//long l;long a[]; 
		ArrayList<ArrayList<Integer>> ob=new ArrayList<>();
		ArrayList<Long> ob2=new ArrayList<>();
		ArrayList<Long> ob3=new ArrayList<>();
		TreeSet<Integer> h=new TreeSet<>();
		HashMap<Integer,Integer> h1=new HashMap<>();
		try{
		while (t-->0)
		{
		    n=sc.nextInt();s=sc.next();G.a1=new int[n+1][26];
		    b1=false;b2=false;m=-1;
		    for(int i=1;i<n+1;i++)
		    {
		        for (int j=0;j<26;j++)
		        G.a1[i][j]=G.a1[i-1][j];
		        G.a1[i][s.charAt(i-1)-'a']++;
		        //o.println(Arrays.toString(G.a1[i]));
		    }
		    o.println(G.bit(0,n,0));
		    //System.out.println();
		    //o.println(ob3);
		    //o.println();
		    h.clear();ob.clear();ob2.clear();ob3.clear();//m.clear();
		}
		}
		catch (Throwable e)
		{
		    e.printStackTrace();
		}
		//o.println("HI");
		
        o.flush();
        o.close();
	}
} 