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

public class aGoodString {
	
	static void calc(char arr[],int i,int j,long cnt,char ch) {
		if(j<i) System.out.println(cnt);
		else {
			int mid = i + (j-i)/2;
			int f1=0,f2=0,f1n=0,f2n=0;
			for(int a=i;a<=mid;a++)
			{
				if(arr[a]==ch) f1++;
				if(arr[a]==ch+1) f1n++;
			}
			for(int a=mid+1;a<=j;a++)
			{
				if(arr[a]==ch) f2++;
				if(arr[a]==ch+1) f2n++;
			}
			if(f1==0&&f2==0 && f1n!=0||f2n!=0)
			{
				if(f1n>=f2n)
				{
					cnt += mid+1-i - f2;ch++;
					calc(arr,i,mid,cnt,ch);
				}
				else 
				{
					cnt += mid+1-i - f1;ch++;
					calc(arr,mid+1,j,cnt,ch);
				}
			}
			else if(f1>=f2)
			{
				cnt += mid+1-i - f1;ch++;
				calc(arr,mid+1,j,cnt,ch);
			}else {
				cnt += mid+1-i - f2;ch++;
				calc(arr,i,mid,cnt,ch);
			}
			
				
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();
		while(t-->0) {
			int n = in.nextInt();
			in.nextLine();
			long cnt = 0;
			char arr[] = in.nextLine().toCharArray();
			if(n!=1) calc(arr,0,n-1,cnt,'a');
			else if(arr[0]=='a') System.out.println(cnt);
			else System.out.println("1");
		}
	}

}




