import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int ntests = in.nextInt();
            for (int itest = 0; itest < ntests; itest++) {
                int len = in.nextInt();
                char[] s = in.nextLine(len).toCharArray();
                int ans = rec(s, 0, s.length - 1, 'a');
                out.println(ans);
            }
        }

        private int rec(char[] s, int le, int ri, char c) {
            if (le == ri) {
                return s[le] == c ? 0 : 1;
            }

            int mid = le + (ri - le) / 2;
            //1
            int ans1 = 0;
            for (int i = le; i <= mid; i++) {
                if (s[i] != c) {
                    ans1++;
                }
            }
            ans1 += rec(s, mid + 1, ri, (char) (c + 1));

            //2
            int ans2 = 0;
            for (int i = mid + 1; i <= ri; i++) {
                if (s[i] != c) {
                    ans2++;
                }
            }
            ans2 += rec(s, le, mid, (char) (c + 1));

            return Math.min(ans1, ans2);
        }

    }

    static class InputReader {
        final InputStream is;
        final byte[] buffer = new byte[1024];
        int curCharIdx;
        int nChars;

        public InputReader(InputStream is) {
            this.is = is;
        }

        public int read() {
            if (curCharIdx >= nChars) {
                try {
                    curCharIdx = 0;
                    nChars = is.read(buffer);
                    if (nChars == -1) {
                        return -1;
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return buffer[curCharIdx++];
        }

        public int nextInt() {
            int sign = 1;
            int c = skipDelims();
            if (c == '-') {
                sign = -1;
                c = read();
                if (isDelim(c)) {
                    throw new RuntimeException("Incorrect format");
                }
            }
            int val = 0;
            while (c != -1 && !isDelim(c)) {
                if (!isDigit(c)) {
                    throw new RuntimeException("Incorrect format");
                }
                val = 10 * val + (c - '0');
                c = read();
            }
            return val * sign;
        }

        public String nextLine(int size) {
            int c = read();
            while (c == '\n' || c == '\t' || c == '\r') {
                c = read();
            }
            if (c == -1) {
                return null;
            }
            StringBuilder sb = new StringBuilder(size);
            while (c != -1 && c != '\n' && c != '\t' && c != '\r') {
                sb.appendCodePoint(c);
                c = read();
            }
            return sb.toString();
        }

        private final int skipDelims() {
            int c = read();
            while (isDelim(c)) {
                c = read();
            }
            return c;
        }

        private static boolean isDelim(final int c) {
            return c == ' ' ||
                   c == '\n' ||
                   c == '\t' ||
                   c == '\r' ||
                   c == '\f';
        }

        private static boolean isDigit(final int c) {
            return '0' <= c && c <= '9';
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int ntests = in.nextInt();
            for (int itest = 0; itest < ntests; itest++) {
                int len = in.nextInt();
                char[] s = in.nextLine().toCharArray();
                int ans = rec(s, 0, s.length - 1, 'a');
                out.println(ans);
            }
        }

        private int rec(char[] s, int le, int ri, char c) {
            if (le == ri) {
                return s[le] == c ? 0 : 1;
            }

            int mid = le + (ri - le) / 2;
            //1
            int ans1 = 0;
            for (int i = le; i <= mid; i++) {
                if (s[i] != c) {
                    ans1++;
                }
            }
            ans1 += rec(s, mid + 1, ri, (char) (c + 1));

            //2
            int ans2 = 0;
            for (int i = mid + 1; i <= ri; i++) {
                if (s[i] != c) {
                    ans2++;
                }
            }
            ans2 += rec(s, le, mid, (char) (c + 1));

            return Math.min(ans1, ans2);
        }

    }

    static class InputReader {
        final InputStream is;
        final byte[] buffer = new byte[1024];
        int curCharIdx;
        int nChars;

        public InputReader(InputStream is) {
            this.is = is;
        }

        public int read() {
            if (curCharIdx >= nChars) {
                try {
                    curCharIdx = 0;
                    nChars = is.read(buffer);
                    if (nChars == -1) {
                        return -1;
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return buffer[curCharIdx++];
        }

        public int nextInt() {
            int sign = 1;
            int c = skipDelims();
            if (c == '-') {
                sign = -1;
                c = read();
                if (isDelim(c)) {
                    throw new RuntimeException("Incorrect format");
                }
            }
            int val = 0;
            while (c != -1 && !isDelim(c)) {
                if (!isDigit(c)) {
                    throw new RuntimeException("Incorrect format");
                }
                val = 10 * val + (c - '0');
                c = read();
            }
            return val * sign;
        }

        public String nextLine() {
            return nextLine(16);
        }

        public String nextLine(int size) {
            int c = read();
            while (c == '\n' || c == '\t' || c == '\r') {
                c = read();
            }
            if (c == -1) {
                return null;
            }
            StringBuilder sb = new StringBuilder(size);
            while (c != -1 && c != '\n' && c != '\t' && c != '\r') {
                sb.appendCodePoint(c);
                c = read();
            }
            return sb.toString();
        }

        private final int skipDelims() {
            int c = read();
            while (isDelim(c)) {
                c = read();
            }
            return c;
        }

        private static boolean isDelim(final int c) {
            return c == ' ' ||
                   c == '\n' ||
                   c == '\t' ||
                   c == '\r' ||
                   c == '\f';
        }

        private static boolean isDigit(final int c) {
            return '0' <= c && c <= '9';
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int ntests = in.nextInt();
            for (int itest = 0; itest < ntests; itest++) {
                int len = in.nextInt();
                char[] s = in.nextLine(len).toCharArray();
                int ans = rec(s, 0, s.length - 1, 'a');
                out.println(ans);
            }
        }

        private int rec(char[] s, int le, int ri, char c) {
            if (le == ri) {
                return s[le] == c ? 0 : 1;
            }

            int mid = le + (ri - le) / 2;
            //1
            int ans1 = 0;
            for (int i = 0; i <= mid; i++) {
                if (s[i] != c) {
                    ans1++;
                }
            }
            ans1 += rec(s, mid + 1, ri, (char) (c + 1));

            //2
            int ans2 = 0;
            for (int i = mid + 1; i <= ri; i++) {
                if (s[i] != c) {
                    ans2++;
                }
            }
            ans2 += rec(s, le, mid, (char) (c + 1));

            return Math.min(ans1, ans2);
        }

    }

    static class InputReader {
        final InputStream is;
        final byte[] buffer = new byte[1024];
        int curCharIdx;
        int nChars;

        public InputReader(InputStream is) {
            this.is = is;
        }

        public int read() {
            if (curCharIdx >= nChars) {
                try {
                    curCharIdx = 0;
                    nChars = is.read(buffer);
                    if (nChars == -1) {
                        return -1;
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return buffer[curCharIdx++];
        }

        public int nextInt() {
            int sign = 1;
            int c = skipDelims();
            if (c == '-') {
                sign = -1;
                c = read();
                if (isDelim(c)) {
                    throw new RuntimeException("Incorrect format");
                }
            }
            int val = 0;
            while (c != -1 && !isDelim(c)) {
                if (!isDigit(c)) {
                    throw new RuntimeException("Incorrect format");
                }
                val = 10 * val + (c - '0');
                c = read();
            }
            return val * sign;
        }

        public String nextLine(int size) {
            int c = read();
            while (c == '\n' || c == '\t' || c == '\r') {
                c = read();
            }
            if (c == -1) {
                return null;
            }
            StringBuilder sb = new StringBuilder(size);
            while (c != -1 && c != '\n' && c != '\t' && c != '\r') {
                sb.appendCodePoint(c);
                c = read();
            }
            return sb.toString();
        }

        private final int skipDelims() {
            int c = read();
            while (isDelim(c)) {
                c = read();
            }
            return c;
        }

        private static boolean isDelim(final int c) {
            return c == ' ' ||
                   c == '\n' ||
                   c == '\t' ||
                   c == '\r' ||
                   c == '\f';
        }

        private static boolean isDigit(final int c) {
            return '0' <= c && c <= '9';
        }

    }
}


import java.util.Scanner;

public class D{
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int t = input.nextInt();
		// input.nextLine();
		while(t-- != 0){
			int n = input.nextInt();
			input.nextLine();
			String s = input.nextLine();
			System.out.println(solve(s, 'a', 0));
			answer = Integer.MAX_VALUE;
		}
	}

	public static int answer = Integer.MAX_VALUE;

	public static int solve(String s, char ch, int ans){
		if(ans > answer){
			return answer;
		}
		int half = s.length()/2;
		int frst = 0;
		int scnd = 0;
		if(s.length() == 1){
			if(s.charAt(0) == ch){
				answer = Math.min(answer, ans);
				return ans;
			}
			ans += 1;
			answer = Math.min(answer, ans);
			return ans;
		}
		for(int i = 0; i < half; i++){
			if(s.charAt(i) == ch){
				frst++;
			}
			if(s.charAt(half+i) == ch){
				scnd++;
			}
		}
		int ans1 = ans+half-frst;
		int ans2 = ans+half-scnd;
		ch++;
		return Math.min(solve(s.substring(half), ch, ans1), solve(s.substring(0, half), ch, ans2));

	}
}


import java.util.Scanner;

public class D{
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int t = input.nextInt();
		// input.nextLine();
		while(t-- != 0){
			int n = input.nextInt();
			input.nextLine();
			String s = input.nextLine();
			if(s.length() == 1){
				if(s.charAt(0) == 'a'){
					System.out.println(0);
				}
				else
					System.out.println(1);
				continue;
			}
			System.out.println(solve(s, 'a', 0));

		}
	}

	public static int solve(String s, char ch, int ans){
		int half = s.length()/2;
		int frst = 0;
		int scnd = 0;
		if(s.length() == 1){
			if(s.charAt(0) == ch){
				return ans;
			}
			return ++ans;
		}
		for(int i = 0; i < half; i++){
			if(s.charAt(i) == ch){
				frst++;
			}
			if(s.charAt(half*2-1-i) == ch){
				scnd++;
			}
		}
		// System.out.println(frst + " " + ch + " " + ans);
		// System.out.println(scnd + " " + ch + " " + ans);
		// System.out.println("---------------------");
		if(frst > scnd){
			ans += half - frst;
			return solve(s.substring(half), ++ch, ans);
		}
		if(scnd > frst){
			ans += half - scnd;
			return solve(s.substring(0, half), ++ch, ans);
		}
		else{
			ans += half - scnd;
			return Math.min(solve(s.substring(half), ++ch, ans), solve(s.substring(0, half), ++ch, ans));
		}

	}
}


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

public class codeforces {

    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        int T=sc.nextInt();
        for (int t = 0; t < T; t++) {
            int n=sc.nextInt();
            String str=sc.nextLine();
            out.println(recur('a',str));
        }

        out.close();
    }

    public static int recur(char ch,String str) {
        int s=0;
        int e=str.length();
        if (s==e-1) {
            return str.charAt(s)==ch?0:1;
        }

        int ryt=recur((char)(ch+1),str.substring(e/2,e));
        int lft=recur((char)(ch+1),str.substring(s,e/2));
        for (int i = e/2; i < e; i++) {
            if (str.charAt(i)!=ch)
                lft++;
        }
        for (int i = 0; i < e/2; i++) {
            if (str.charAt(i)!=ch)
                ryt++;
        }
//        System.out.println(lft+" "+ryt+" "+ch+" "+" "+str+" "+" ");
        return Math.min(lft,ryt);
    }

	static class InputReader {

            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int curChar, snumChars;
            private SpaceCharFilter filter;

            public InputReader(InputStream stream) {
                this.stream = stream;
            }

            public int snext() {
                if (snumChars == -1)
                    throw new InputMismatchException();
                if (curChar >= snumChars) {
                    curChar = 0;
                    try {
                        snumChars = stream.read(buf);
                    } catch (IOException e) {
                        throw new InputMismatchException();
                    }
                    if (snumChars <= 0)
                        return -1;
                }
                return buf[curChar++];
            }

            public int nextInt() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = snext();
                }
                int res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
            }

            public long nextLong() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = snext();
                }
                long res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
            }

            public int[] nextIntArray(int n) {
                int a[] = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = nextInt();
                }
                return a;
            }

            public String readString() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = snext();
                } while (!isSpaceChar(c));
                return res.toString();
            }

            public String nextLine() {
                int c = snext();
                while (isSpaceChar(c))
                    c = snext();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = snext();
                } while (!isEndOfLine(c));
                return res.toString();
            }

            public double nextDouble() {
                return (Double.parseDouble(readString()));
            }

            public boolean isSpaceChar(int c) {
                if (filter != null)
                    return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }

            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }

            public interface SpaceCharFilter {
                public boolean isSpaceChar(int ch);
            }
        }
    static private PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
    static int mod = 1000000000 + 7;

}


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

public class codeforces {

    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        int T=sc.nextInt();
        for (int t = 0; t < T; t++) {
            int n=sc.nextInt();
            String str=sc.nextLine();
            recur('a',str);
            out.println(total);
            total=0;
        }

        out.close();
    }
    static int total=0;

    public static void recur(char ch,String str) {
        int s=0;
        int e=str.length();
        int fh=0;
        int sh=0;
//        System.out.println(s+" "+e+" "+ch+" "+" "+str+" "+total);
        if (s==e-1) {
            total+=str.charAt(s)==ch?0:1;
            return;
        }
        for (int i = s; i < e/2; i++) {
            if (str.charAt(i)!=ch)
                fh++;
        }
        for (int i = e-1; i >= e/2; i--) {
            if (str.charAt(i)!=ch)
                sh++;
        }
        total+=Math.min(fh,sh);
        if(Math.min(fh,sh)==fh) {
            recur(++ch,str.substring(e/2,e));
        }
        else {
            recur(++ch,str.substring(s,e/2));
        }
    }

	static class InputReader {

            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int curChar, snumChars;
            private SpaceCharFilter filter;

            public InputReader(InputStream stream) {
                this.stream = stream;
            }

            public int snext() {
                if (snumChars == -1)
                    throw new InputMismatchException();
                if (curChar >= snumChars) {
                    curChar = 0;
                    try {
                        snumChars = stream.read(buf);
                    } catch (IOException e) {
                        throw new InputMismatchException();
                    }
                    if (snumChars <= 0)
                        return -1;
                }
                return buf[curChar++];
            }

            public int nextInt() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = snext();
                }
                int res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
            }

            public long nextLong() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = snext();
                }
                long res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
            }

            public int[] nextIntArray(int n) {
                int a[] = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = nextInt();
                }
                return a;
            }

            public String readString() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = snext();
                } while (!isSpaceChar(c));
                return res.toString();
            }

            public String nextLine() {
                int c = snext();
                while (isSpaceChar(c))
                    c = snext();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = snext();
                } while (!isEndOfLine(c));
                return res.toString();
            }

            public double nextDouble() {
                return (Double.parseDouble(readString()));
            }

            public boolean isSpaceChar(int c) {
                if (filter != null)
                    return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }

            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }

            public interface SpaceCharFilter {
                public boolean isSpaceChar(int ch);
            }
        }
    static private PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
    static int mod = 1000000000 + 7;

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class Solution1385D {
  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    Solver1385D solver = new Solver1385D();
    int n = in.nextInt();
    for (int i = 0; i < n; i++) {
      solver.solve(i, in, out);
    }
    out.close();
  }

  static class Solver1385D {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int len = in.nextInt();
      String s = in.next();
      Map<Integer, Map<Integer, Map<Character, Integer>>> cache = new HashMap<>();
      Map<Integer, Map<Integer, Map<Character, Integer>>> diffCache = new HashMap<>();

      Set<Character> chars = new HashSet<>();

      out.println(minChange(s, 0, len, 'a', cache, diffCache));
    }

    private int minChange(String s, int start, int len, char c,
        Map<Integer, Map<Integer, Map<Character, Integer>>> cache,
        Map<Integer, Map<Integer, Map<Character, Integer>>> diffCache) {
      if (len == 1) {
        if (s.charAt(start) == c) {
          return 0;
        }
        return 1;
      }

      if (cache.containsKey(start) && cache.get(start).containsKey(len)
          && cache.get(start).get(len).containsKey(c)) {
        return cache.get(start).get(len).get(c);
      }

      if (!cache.containsKey(start)) {
        cache.put(start, new HashMap<>());
      }

      Map<Integer, Map<Character, Integer>> startMap = cache.get(start);
      Map<Character, Integer> charMap = startMap.get(len);
      if (charMap == null) {
        charMap = new HashMap<>();
        startMap.put(len, charMap);
      }

      int result = charDiff(s, start, len / 2, c, diffCache)
          + minChange(s, start + len / 2, len / 2, (char)(c+1), cache, diffCache);

      int tmp = charDiff(s, start + len / 2, len / 2, c, diffCache);

      if (tmp < result) {
        result = Math.min(result,
            tmp + minChange(s, start, len / 2, (char)(c+1), cache, diffCache));
      }

      charMap.put(c, result);

      return result;
    }

    private int charDiff(String s, int start, int len, char c,
        Map<Integer, Map<Integer, Map<Character, Integer>>> cache) {
      if (cache.containsKey(start) && cache.get(start).containsKey(len)
          && cache.get(start).get(len).containsKey(c)) {
        return cache.get(start).get(len).get(c);
      }

      if (!cache.containsKey(start)) {
        cache.put(start, new HashMap<>());
      }

      Map<Integer, Map<Character, Integer>> startMap = cache.get(start);
      Map<Character, Integer> charMap = startMap.get(len);
      if (charMap == null) {
        charMap = new HashMap<>();
        startMap.put(len, charMap);
      }

      int result = 0;

      for (int i = start; i < start + len; i++) {
        if (s.charAt(i) != c) {
          result++;
        }
      }
      charMap.put(c, result);

      return result;
    }
  }

  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());
    }
  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class Solution1385D {
  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    Solver1385D solver = new Solver1385D();
    int n = in.nextInt();
    for (int i = 0; i < n; i++) {
      solver.solve(i, in, out);
    }
    out.close();
  }

  static class Solver1385D {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int len = in.nextInt();
      String s = in.next();
      Map<Integer, Map<Integer, Map<Character, Integer>>> cache = new HashMap<>();
      Map<Integer, Map<Integer, Map<Character, Integer>>> diffCache = new HashMap<>();

      Set<Character> chars = new HashSet<>();

      out.println(minChange(s, 0, len, 'a', cache, diffCache));
    }

    private int minChange(String s, int start, int len, char c,
        Map<Integer, Map<Integer, Map<Character, Integer>>> cache,
        Map<Integer, Map<Integer, Map<Character, Integer>>> diffCache) {
      if (len == 1) {
        if (s.charAt(start) == c) {
          return 0;
        }
        return 1;
      }

      if (cache.containsKey(start) && cache.get(start).containsKey(len)
          && cache.get(start).get(len).containsKey(c)) {
        return cache.get(start).get(len).get(c);
      }

      if (!cache.containsKey(start)) {
        cache.put(start, new HashMap<>());
      }

      Map<Integer, Map<Character, Integer>> startMap = cache.get(start);
      Map<Character, Integer> charMap = startMap.get(len);
      if (charMap == null) {
        charMap = new HashMap<>();
        startMap.put(len, charMap);
      }

      int result = charDiff(s, start, len / 2, c, diffCache)
          + minChange(s, start + len / 2, len / 2, (char)(c+1), cache, diffCache);

      int tmp = charDiff(s, start + len / 2, len / 2, c, diffCache);

      if (tmp < result) {
        result = Math.min(result,
            tmp + minChange(s, start, len / 2, (char)(c+1), cache, diffCache));
      }

      charMap.put(c, result);

      return result;
    }

    private int charDiff(String s, int start, int len, char c,
        Map<Integer, Map<Integer, Map<Character, Integer>>> cache) {
      if (cache.containsKey(start) && cache.get(start).containsKey(len)
          && cache.get(start).get(len).containsKey(c)) {
        return cache.get(start).get(len).get(c);
      }

      if (!cache.containsKey(start)) {
        cache.put(start, new HashMap<>());
      }

      Map<Integer, Map<Character, Integer>> startMap = cache.get(start);
      Map<Character, Integer> charMap = startMap.get(len);
      if (charMap == null) {
        charMap = new HashMap<>();
        startMap.put(len, charMap);
      }

      int result = 0;

      for (int i = start; i < start + len; i++) {
        if (s.charAt(i) != c) {
          result++;
        }
      }
      charMap.put(c, result);

      return result;
    }
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 262144);
      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());
    }
  }
}


import java.util.Scanner;

public class CF_Round_656_Div3_ProblemD_ {
    public static void main(String[] args) {
        process();
    }

    public static void process() {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for(int i = 0; i < t; ++i) {
            int n = scanner.nextInt();
            String str = scanner.next();
            int ret = solve(str);
            System.out.println(ret);

        }
    }

    public static int solve(String str) {
        return solve(str.toCharArray(), 0, str.length()-1, 'a');
    }

    public static int solve(char[] arr, int from, int to, char target) {
        if(from == to) {
            if(arr[from] == target) {
                return 0;
            }
            else {
                return 1;
            }
        }
        else {
            char next = (char)(target+1);
            int mid = (from + to)/2;

            int leftCount = 0;
            for(int i = from; i <= mid; ++i) {
                if(arr[i] != target) {
                    leftCount++;
                }
            }
            int rightCount = 0;
            for(int i = mid+1; i <= to; ++i) {
                if(arr[i] != target) {
                    rightCount++;
                }
            }

            int left = leftCount + solve(arr, mid + 1, to, next);
            int right = solve(arr, from, mid, next) + rightCount;

            return Math.min(left, right);
        }
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class D {

	// C-good String으로 만드는데 필요한 최소 대체 수 반환
	static int aGood(String S, char C) {
		if (S.length() == 1) {return S.charAt(0) != C ? 1 : 0;}
		int mid = S.length() / 2;
		// 1번 조건 만족시키기
		int cand1 = 0;
		String preFix = S.substring(0, mid);
		for (int i = 0; i < preFix.length(); i++)
			if (preFix.charAt(i) != C)
				cand1++;
		cand1 += aGood(S.substring(mid), (char)(C + 1));
		// 2번 조건 만족시키기
		int cand2 = 0;
		preFix = S.substring(mid);
		for (int i = 0; i < preFix.length(); i++)
			if (preFix.charAt(i) != C)
				cand2++;
		cand2 += aGood(S.substring(0, mid), (char)(C + 1));
		return Math.min(cand1, cand2);
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		int T = Integer.parseInt(br.readLine());
		for (int c = 0; c < T; c++) {
			br.readLine();
			String S = br.readLine();
			bw.write(String.valueOf(aGood(S, 'a')));
			bw.newLine();
		}
		bw.close();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public final class CodeForces {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        while(t-->0) {
            int n = Integer.parseInt(br.readLine());
            String s = br.readLine();
            if(n > 1) {
                System.out.println(solve(s.substring(0, n / 2), s.substring(n / 2), 'a'));
            } else {
                System.out.println(s.charAt(0) == 'a' ? 0 : 1);
            }
        }
        br.close();
    }

    private static int solve(String s1, String s2, char c) {
        int count1 = 0, count2 = 0;
        if(s1.length() == 1) {
            char[] match = new char[2];
            match[0] = c;
            match[1] = (char) (c + 1);
            Arrays.sort(match);
            char[] a = new char[2];
            a[0] = s1.charAt(0);
            a[1] = s2.charAt(0);
            Arrays.sort(a);
            if(a[0] == match[0] && a[1] == match[1])
                return 0;
            else if(a[0] == match[0])
                return 1;
            else if(a[1] == match[1])
                return 1;
            else
                return 2;
        }
        for(int i=0; i<s1.length(); i++) {
            if(s1.charAt(i) != c)
                count1++;
            if(s2.charAt(i) != c)
                count2++;
        }
        char next = (char) (c + 1);
        return Math.min(count1 + solve(s2.substring(0, s2.length()/2), s2.substring(s2.length()/2), next), count2 + solve(s1.substring(0, s1.length()/2), s1.substring(s1.length()/2), next));
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public final class CodeForces {
    static int ans;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        while(t-->0) {
            int n = Integer.parseInt(br.readLine());
            String s = br.readLine();
            ans = Integer.MAX_VALUE;
            if(n > 1) {
                solve(s, 'a', 0);
                System.out.println(ans);
            } else {
                System.out.println(s.charAt(0) == 'a' ? 0 : 1);
            }
        }
        br.close();
    }

    private static void solve(String s, char c, int val) {
        int count1 = 0, count2 = 0;
        if(s.length() == 1) {
            if(s.charAt(0) == c) {
                ans = Math.min(ans, val);
            } else {
                ans = Math.min(ans, val+1);
            }
            return;
        }
        String s1 = s.substring(0, s.length()/2);
        String s2 = s.substring(s.length()/2);
        for(int i=0; i<s1.length(); i++) {
            if(s1.charAt(i) == c)
                count1++;
            if(s2.charAt(i) == c)
                count2++;
        }
        char next = (char) (c + 1);
        solve(s2, next, val + s1.length() - count1);
        solve(s1, next, val + s2.length() - count2);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public final class CodeForces {
    static int count;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        while(t-->0) {
            int n = Integer.parseInt(br.readLine());
            String s = br.readLine();
            count = 0;
            if(n > 1) {
                solve(s.substring(0, n / 2), s.substring(n / 2, n), 'a');
            } else {
                if(s.charAt(0) != 'a')
                    count++;
            }
            System.out.println(count);
        }
        br.close();
    }

    private static void solve(String s1, String s2, char c) {
        //System.out.println(s1 + " " + s2);
        int count1 = 0, count2 = 0;
        if(s1.length() == 0 && s2.length() == 0)
            return;
        if(s1.length() == 1) {
            char next = (char) (c + 1);
            char[] a = new char[2];
            a[0] = s1.charAt(0);
            a[1] = s2.charAt(0);
            Arrays.sort(a);
            char[] match = new char[2];
            match[0] = next;
            match[1] = c;
            Arrays.sort(match);
            if(a[0] == match[0] && a[1] == match[1])
                return;
            else if(a[0] == match[0]) {
                count++;
                return;
            } else if(a[1] == match[1]) {
                count++;
                return;
            } else {
                count += 2;
                return;
            }
        }
        char next = (char) (c + 1);
        int nextCount1 = 0, nextCount2 = 0;
        for(int i=0; i<s1.length(); i++) {
            if(s1.charAt(i) == c)
                count1++;
            if(s2.charAt(i) == c)
                count2++;
            if(s1.charAt(i) == next)
                nextCount1++;
            if(s2.charAt(i) == next)
                nextCount2++;
        }
        if(count1 > count2) {
            for(int j=0; j<s1.length(); j++) {
                if(s1.charAt(j) != c) {
                    count++;
                }
            }
            solve(s2.substring(0, s2.length()/2), s2.substring(s2.length()/2), (char) (c+1));
        } else if(count1 < count2){
            for(int j=0; j<s2.length(); j++) {
                if(s2.charAt(j) != c)
                    count++;
            }
            solve(s1.substring(0, s1.length()/2), s1.substring(s1.length()/2), (char) (c+1));
        } else {
            if(nextCount1 > nextCount2) {
                for(int j=0; j<s2.length(); j++) {
                    if(s2.charAt(j) != c)
                        count++;
                }
                solve(s1.substring(0, s1.length()/2), s1.substring(s1.length()/2), next);
            } else {
                for(int j=0; j<s1.length(); j++) {
                    if(s1.charAt(j) != c)
                        count++;
                }
                solve(s2.substring(0, s2.length()/2), s2.substring(s2.length()/2), (char) (c+1));
            }
        }
    }
}


import com.sun.org.apache.xpath.internal.SourceTree;
import com.sun.org.apache.xpath.internal.functions.FuncFalse;
import javafx.util.Pair;

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

import static java.lang.Math.*;

public class Contest {
    public static class pair implements Comparable<pair> {
        long l;
        long r;

        public pair(long lef, long ri) {
            l = lef;
            r = ri;
        }

        @Override
        public int compareTo(pair p) {
            if (l == p.l)
                return Long.compare(r, p.r);
            return Long.compare(l, p.l);
        }
    }

    static int n, m;
    static ArrayList<Integer>[] adj;
    static int dist[];
    static int parent[];
    static long inf = (long) 1e18;
    static int INF = (int) 1e9;

    public static boolean isSimilar(char[] Arr, int s, int k) {
        for (int i = s; i < k - 1; i++) {
            if (Arr[i + 1] != Arr[i])
                return false;
        }
        return true;
    }

    public static int ciel(int d, int mod) {
        if (d % mod == 0)
            return d / mod;
        return (d / mod) + 1;
    }

    public static long gcd(long u, long v) {
        if (v == 0)
            return u;
        return gcd(v, u % v);
    }

    static int k, Arr[], lefAcc[], riAcc[];
    static PrintWriter pw;

    static long memo[][];
    static char[][] Matrix;
    static int[] dx = new int[]{-1, 1, 0, 0};

    static int[] dy = new int[]{0, 0, -1, 1};

    static boolean valid(int i, int j) {

        return i != -1 && j != -1 && i != n && j != m;

    }

    static boolean[][] vis = new boolean[n][m];

    static void dfs2(int i, int j) {

        vis[i][j] = true;                    //mark as visited

        for (int k = 0; k < 4; ++k) {

            int x = i + dx[k], y = j + dy[k];

            if (valid(x, y) && Matrix[x][y] != '#' && !vis[x][y])

                dfs2(x, y);

        }

    }

    public static int getnum(int[][] matrix, int i, int j) {
        int c = 0;

        for (int k = 0; k < 4; ++k) {

            int x = i + dx[k], y = j + dy[k];

            if (valid(x, y))
                c++;

        }
        return c;
    }

    static String str;

    public static int howManyChar(char c, int lo, int hi) {
        int cnt = 0;
        for (int i = lo; i <= hi; i++) {
            if (str.charAt(i) == c) cnt++;
        }
        return (hi - lo + 1) - cnt;
    }

    public static long divCon(int lo, int hi, char c) {
        if (lo == hi)
            return c == str.charAt(lo) ? 0 : 1;
        int mid = (lo + hi) >> 1;
        char next= (char) (c+1);
        return min(howManyChar(c, lo, mid) + divCon(mid + 1, hi, next),
                howManyChar(c, mid + 1, hi) + divCon(lo, mid, next));
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int t = sc.nextInt();
        while (t-- > 0) {

            int n = sc.nextInt();
          str=sc.next();
          pw.println(divCon(0, n-1, 'a'));

        }

        pw.close();

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        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, IOException {
            return br.ready();
        }

    }
}


import com.sun.org.apache.xpath.internal.SourceTree;
import com.sun.org.apache.xpath.internal.functions.FuncFalse;
import javafx.util.Pair;

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

import static java.lang.Math.*;

public class Contest {
    public static class pair implements Comparable<pair> {
        long l;
        long r;

        public pair(long lef, long ri) {
            l = lef;
            r = ri;
        }

        @Override
        public int compareTo(pair p) {
            if (l == p.l)
                return Long.compare(r, p.r);
            return Long.compare(l, p.l);
        }
    }

    static int n, m;
    static ArrayList<Integer>[] adj;
    static int dist[];
    static int parent[];
    static long inf = (long) 1e18;
    static int INF = (int) 1e9;

    public static boolean isSimilar(char[] Arr, int s, int k) {
        for (int i = s; i < k - 1; i++) {
            if (Arr[i + 1] != Arr[i])
                return false;
        }
        return true;
    }

    public static int ciel(int d, int mod) {
        if (d % mod == 0)
            return d / mod;
        return (d / mod) + 1;
    }

    public static long gcd(long u, long v) {
        if (v == 0)
            return u;
        return gcd(v, u % v);
    }

    static int k, Arr[], lefAcc[], riAcc[];
    static PrintWriter pw;

    static long memo[][];
    static char[][] Matrix;
    static int[] dx = new int[]{-1, 1, 0, 0};

    static int[] dy = new int[]{0, 0, -1, 1};

    static boolean valid(int i, int j) {

        return i != -1 && j != -1 && i != n && j != m;

    }

    static boolean[][] vis = new boolean[n][m];

    static void dfs2(int i, int j) {

        vis[i][j] = true;                    //mark as visited

        for (int k = 0; k < 4; ++k) {

            int x = i + dx[k], y = j + dy[k];

            if (valid(x, y) && Matrix[x][y] != '#' && !vis[x][y])

                dfs2(x, y);

        }

    }

    public static int getnum(int[][] matrix, int i, int j) {
        int c = 0;

        for (int k = 0; k < 4; ++k) {

            int x = i + dx[k], y = j + dy[k];

            if (valid(x, y))
                c++;

        }
        return c;
    }

    static String str;

    public static int howManyChar(char c, int lo, int hi) {
        int cnt = 0;
        for (int i = lo; i <= hi; i++) {
            if (str.charAt(i) == c) cnt++;
        }
        return (hi - lo + 1) - cnt;
    }

    public static long divCon(int lo, int hi, char c) {
        if (lo == hi)
            return c == str.charAt(lo) ? 0 : 1;
        int mid = (lo + hi) >> 1;
        char next= (char) (c+1);
        return min(howManyChar(c, lo, mid) + divCon(mid + 1, hi, next),
                howManyChar(c, mid + 1, hi) + divCon(lo, mid, next));
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int t = sc.nextInt();
        while (t-- > 0) {

            int n = sc.nextInt();
          str=sc.next();
          pw.println(divCon(0, n-1, 'a'));

        }

        pw.close();

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        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++;
            }import com.sun.org.apache.xpath.internal.SourceTree;
import com.sun.org.apache.xpath.internal.functions.FuncFalse;
import javafx.util.Pair;

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

import static java.lang.Math.*;

public class Contest {
    public static class pair implements Comparable<pair> {
        long l;
        long r;

        public pair(long lef, long ri) {
            l = lef;
            r = ri;
        }

        @Override
        public int compareTo(pair p) {
            if (l == p.l)
                return Long.compare(r, p.r);
            return Long.compare(l, p.l);
        }
    }

    static int n, m;
    static ArrayList<Integer>[] adj;
    static int dist[];
    static int parent[];
    static long inf = (long) 1e18;
    static int INF = (int) 1e9;

    public static boolean isSimilar(char[] Arr, int s, int k) {
        for (int i = s; i < k - 1; i++) {
            if (Arr[i + 1] != Arr[i])
                return false;
        }
        return true;
    }

    public static int ciel(int d, int mod) {
        if (d % mod == 0)
            return d / mod;
        return (d / mod) + 1;
    }

    public static long gcd(long u, long v) {
        if (v == 0)
            return u;
        return gcd(v, u % v);
    }

    static int k, Arr[], lefAcc[], riAcc[];
    static PrintWriter pw;

    static long memo[][];
    static char[][] Matrix;
    static int[] dx = new int[]{-1, 1, 0, 0};

    static int[] dy = new int[]{0, 0, -1, 1};

    static boolean valid(int i, int j) {

        return i != -1 && j != -1 && i != n && j != m;

    }

    static boolean[][] vis = new boolean[n][m];

    static void dfs2(int i, int j) {

        vis[i][j] = true;                    //mark as visited

        for (int k = 0; k < 4; ++k) {

            int x = i + dx[k], y = j + dy[k];

            if (valid(x, y) && Matrix[x][y] != '#' && !vis[x][y])

                dfs2(x, y);

        }

    }

    public static int getnum(int[][] matrix, int i, int j) {
        int c = 0;

        for (int k = 0; k < 4; ++k) {

            int x = i + dx[k], y = j + dy[k];

            if (valid(x, y))
                c++;

        }
        return c;
    }

    static String str;

    public static int howManyChar(char c, int lo, int hi) {
        int cnt = 0;
        for (int i = lo; i <= hi; i++) {
            if (str.charAt(i) == c) cnt++;
        }
        return (hi - lo + 1) - cnt;
    }

    public static long divCon(int lo, int hi, char c) {
        if (lo == hi)
            return c == str.charAt(lo) ? 0 : 1;
        int mid = (lo + hi) >> 1;
        char next= (char) (c+1);
        return min(howManyChar(c, lo, mid) + divCon(mid + 1, hi, next),
                howManyChar(c, mid + 1, hi) + divCon(lo, mid, next));
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int t = sc.nextInt();
        while (t-- > 0) {

            int n = sc.nextInt();
          str=sc.next();
          pw.println(divCon(0, n-1, 'a'));

        }

        pw.close();

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        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, IOException {
            return br.ready();
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pranay2516
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        char s;

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            s = in.next().toCharArray();
            out.println(calc('a', 0, n - 1));
        }

        int calc(char c, int l, int r) {
            if (l == r) return s[l] == c ? 0 : 1;
            int lcnt = 0, rcnt = 0, mid = (l + r + 1) / 2;
            for (int i = l; i < mid; i++) if (s[i] != c) lcnt++;
            for (int i = mid; i <= r; ++i) if (s[i] != c) rcnt++;
            c++;
            return Math.min(lcnt + calc(c, mid, r), rcnt + calc(c, l, mid - 1));
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pranay2516
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        char[] s;

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            s = in.next().toCharArray();
            out.println(calc('a', 0, n - 1));
        }

        int calc(char c, int l, int r) {
            if (l == r) return s[l] == c ? 0 : 1;
            int lcnt = 0, rcnt = 0, mid = (l + r + 1) / 2;
            for (int i = l; i < mid; i++) if (s[i] != c) lcnt++;
            for (int i = mid; i <= r; ++i) if (s[i] != c) rcnt++;
            c++;
            return Math.min(lcnt + calc(c, mid, r), rcnt + calc(c, l, mid - 1));
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


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

public class AGoodString656D{
	static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        private FastReader() {
            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());
        }

	 int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
	}

	int[] nextIntArrayOne(int n) {
				int[] a = new int[n+1];
				for (int i = 1; i < n+1; i++)
					a[i] = nextInt();
				return a;
	}

        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 int freq[][] = new int[131073][26];
	public static void main(String[] args) {
		FastReader s =new FastReader();
		int t = s.nextInt();
		StringBuilder str = new StringBuilder();
		while(t-- >0) {
			int n = s.nextInt();
			String arr = s.nextLine();
			int len = (int)(Math.log(n) / Math.log(2));

			fillFreq(arr,n);

			int ans = func(arr,1,len,'a');

			str.append(ans+"\n");

			for(int [] d : freq) {
				Arrays.fill(d, 0);
			}

		}
		System.out.println(str);
	}

	private static void fillFreq(String arr, int n) {

		for(char c = 'a' ;c <= 'z';c++) {
			if(arr.charAt(0) == c) {
				freq[0][c - 'a'] = 1;
			}else {
				freq[0][c - 'a'] = 0;
			}
		}

		for(int i = 1;i<n;i++) {
			for(char c = 'a' ;c <= 'z';c++) {
				if(arr.charAt(i) == c) {
					freq[i][c - 'a'] = 1 + freq[i - 1][c - 'a'];
				}else {
					freq[i][c - 'a'] = freq[i - 1][c - 'a'];
				}
			}
		}

	}

	private static int func(String arr, int i, int len, char c) {

		if(len == 0) {
			 return c != arr.charAt(i - 1) ? 1 : 0;
		}

		int left = (1 << len - 1) - getCount(i,len - 1,c);
		int right = (1 << len - 1) - getCount(i + (1 << (len - 1)) , len - 1, c);

		return Math.min(left + func(arr,i + (1 << (len  - 1)), len - 1, (char)(c + 1)), right + func(arr,i , len - 1, (char)(c + 1)));
	}

	private static int getCount(int i, int len, char c) {
		int j = i + (1 << len) - 1;

		return freq[j - 1][c - 'a'] -  ((i - 1) == 0  ?  0 : freq[i - 2][c - 'a']);
	}

}


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

public class AGoodString656D{
	static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        private FastReader() {
            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());
        }

	 int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
	}

	int[] nextIntArrayOne(int n) {
				int[] a = new int[n+1];
				for (int i = 1; i < n+1; i++)
					a[i] = nextInt();
				return a;
	}

        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;
        }
    }

	public static void main(String[] args) {
		FastReader s =new FastReader();
		int t = s.nextInt();
		StringBuilder str = new StringBuilder();
		while(t-- >0) {
			int n = s.nextInt();
			String arr = s.nextLine();
			int len = (int)(Math.log(n) / Math.log(2));
			int freq[][] = new int[131073][26];
			fillFreq(arr,n,freq);

			int ans = func(arr,1,len,'a',freq);

			str.append(ans+"\n");

			for(int [] d : freq) {
				Arrays.fill(d, 0);
			}

		}
		System.out.println(str);
	}

	private static void fillFreq(String arr, int n, int[][] freq) {

		for(char c = 'a' ;c <= 'z';c++) {
			if(arr.charAt(0) == c) {
				freq[0][c - 'a'] = 1;
			}else {
				freq[0][c - 'a'] = 0;
			}
		}

		for(int i = 1;i<n;i++) {
			for(char c = 'a' ;c <= 'z';c++) {
				if(arr.charAt(i) == c) {
					freq[i][c - 'a'] = 1 + freq[i - 1][c - 'a'];
				}else {
					freq[i][c - 'a'] = freq[i - 1][c - 'a'];
				}
			}
		}

	}

	private static int func(String arr, int i, int len, char c, int[][] freq) {

		if(len == 0) {
			 return c != arr.charAt(i - 1) ? 1 : 0;
		}

		int left = (1 << len - 1) - getCount(i,len - 1,c,freq);
		int right = (1 << len - 1) - getCount(i + (1 << (len - 1)) , len - 1, c,freq);

		return Math.min(left + func(arr,i + (1 << (len  - 1)), len - 1, (char)(c + 1), freq), right + func(arr,i , len - 1, (char)(c + 1), freq));
	}

	private static int getCount(int i, int len, char c, int[][] freq) {
		int j = i + (1 << len) - 1;

		return freq[j - 1][c - 'a'] -  ((i - 1) == 0  ?  0 : freq[i - 2][c - 'a']);
	}

}


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

public class AGoodString656D{
	static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        private FastReader() {
            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());
        }

	 int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
	}

	int[] nextIntArrayOne(int n) {
				int[] a = new int[n+1];
				for (int i = 1; i < n+1; i++)
					a[i] = nextInt();
				return a;
	}

        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;
        }
    }

	public static void main(String[] args) {
		FastReader s =new FastReader();
		int t = s.nextInt();
		StringBuilder str = new StringBuilder();
		while(t-- >0) {
			int n = s.nextInt();
			String arr = s.nextLine();
			int len = (int)(Math.log(n) / Math.log(2));
			int freq[][] = new int[131073][26];
			fillFreq(arr,n,freq);

			int ans = func(arr,1,len,'a',freq);

			str.append(ans+"\n");

		}
		System.out.println(str);
	}

	private static void fillFreq(String arr, int n, int[][] freq) {

		for(char c = 'a' ;c <= 'z';c++) {
			if(arr.charAt(0) == c) {
				freq[0][c - 'a'] = 1;
			}else {
				freq[0][c - 'a'] = 0;
			}
		}

		for(int i = 1;i<n;i++) {
			for(char c = 'a' ;c <= 'z';c++) {
				if(arr.charAt(i) == c) {
					freq[i][c - 'a'] = 1 + freq[i - 1][c - 'a'];
				}else {
					freq[i][c - 'a'] = freq[i - 1][c - 'a'];
				}
			}
		}

	}

	private static int func(String arr, int i, int len, char c, int[][] freq) {

		if(len == 0) {
			 return c != arr.charAt(i - 1) ? 1 : 0;
		}

		int left = (1 << len - 1) - getCount(i,len - 1,c,freq);
		int right = (1 << len - 1) - getCount(i + (1 << (len - 1)) , len - 1, c,freq);

		return Math.min(left + func(arr,i + (1 << (len  - 1)), len - 1, (char)(c + 1), freq), right + func(arr,i , len - 1, (char)(c + 1), freq));
	}

	private static int getCount(int i, int len, char c, int[][] freq) {
		int j = i + (1 << len) - 1;

		return freq[j - 1][c - 'a'] -  ((i - 1) == 0  ?  0 : freq[i - 2][c - 'a']);
	}

}


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

public class AGoodString656D{
	static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        private FastReader() {
            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());
        }

	 int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
	}

	int[] nextIntArrayOne(int n) {
				int[] a = new int[n+1];
				for (int i = 1; i < n+1; i++)
					a[i] = nextInt();
				return a;
	}

        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;
        }
    }

	public static void main(String[] args) {
		FastReader s =new FastReader();
		int t = s.nextInt();
		StringBuilder str = new StringBuilder();
		while(t-- >0) {
			int n = s.nextInt();
			String arr = s.nextLine();
			int len = (int)(Math.log(n) / Math.log(2));
			int freq[][] = new int[n][26];
			fillFreq(arr,n,freq);

			int ans = func(arr,1,len,'a',freq);

			str.append(ans+"\n");

		}
		System.out.println(str);
	}

	private static void fillFreq(String arr, int n, int[][] freq) {

		for(char c = 'a' ;c <= 'z';c++) {
			if(arr.charAt(0) == c) {
				freq[0][c - 'a'] = 1;
			}else {
				freq[0][c - 'a'] = 0;
			}
		}

		for(int i = 1;i<n;i++) {
			for(char c = 'a' ;c <= 'z';c++) {
				if(arr.charAt(i) == c) {
					freq[i][c - 'a'] = 1 + freq[i - 1][c - 'a'];
				}else {
					freq[i][c - 'a'] = freq[i - 1][c - 'a'];
				}
			}
		}

	}

	private static int func(String arr, int i, int len, char c, int[][] freq) {

		if(len == 0) {
			 return c != arr.charAt(i - 1) ? 1 : 0;
		}

		int left = (1 << len - 1) - getCount(i,len - 1,c,freq);
		int right = (1 << len - 1) - getCount(i + (1 << (len - 1)) , len - 1, c,freq);

		return Math.min(left + func(arr,i + (1 << (len  - 1)), len - 1, (char)(c + 1), freq), right + func(arr,i , len - 1, (char)(c + 1), freq));
	}

	private static int getCount(int i, int len, char c, int[][] freq) {
		int j = i + (1 << len) - 1;

		return freq[j - 1][c - 'a'] -  ((i - 1) == 0  ?  0 : freq[i - 2][c - 'a']);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Objects;
import java.util.StringTokenizer;
import java.util.function.BiFunction;
import java.util.function.Function;

public class Main {

    static BiFunction<Integer, Integer, Integer> ADD = (x, y) -> (x + y);
    static BiFunction<ArrayList<Integer>, ArrayList<Integer>, ArrayList<Integer>> ADD_ARRAY_LIST = (x, y) -> {
        x.addAll(y);
        return x;
    };

    static Function<Pair<Integer, Integer>, Integer> GET_FIRST = (x) -> (x.first);
    static Function<Pair<Integer, Integer>, Integer> GET_SECOND = (x) -> (x.second);
    static Comparator<Pair<Integer, Integer>> C = Comparator.comparing(GET_FIRST).thenComparing(GET_SECOND);

    public static void main(String[] args) throws Exception {
        long startTime = System.nanoTime();
        int t = in.nextInt();
        while (t-- > 0) {
            solve();
        }
        long endTime = System.nanoTime();
        err.println("Execution Time : +" + (endTime - startTime) / 1000000 + " ms");
        exit(0);
    }

    static void solve() {
        int n = in.nextInt();
        String s = in.next();
        out.println(calc(s, 'a'));
    }

    static int calc(String s, char c) {
        if (s.length() == 1) {
            if (s.charAt(0) == c) {
                return 0;
            }
            return 1;
        }
        int mid = s.length() / 2;
        char next = (char) (c + 1);
        int count_l = calc(s.substring(0, mid), next);
        count_l += s.length() / 2 - count(s.substring(mid), c);
        int count_r = calc(s.substring(mid), next);
        count_r += s.length() / 2 - count(s.substring(0, mid), c);
        return (Math.min(count_l, count_r));
    }

    static int count(final String substring, final char c) {
        int ans = 0;
        for (int i = 0; i < substring.length(); i++) {
            if (substring.charAt(i) == c) {
                ans++;
            }
        }
        return ans;
    }

    static void debug(Object... args) {
        for (Object a : args) {
            out.println(a);
        }
    }

    static void y() {
        out.println("YES");
    }

    static void n() {
        out.println("NO");
    }

    static <T> T min(T a, T b, Comparator<T> C) {
        if (C.compare(a, b) <= 0) {
            return a;
        }
        return b;
    }

    static <T> T max(T a, T b, Comparator<T> C) {
        if (C.compare(a, b) >= 0) {
            return a;
        }
        return b;
    }

    static void fail() {
        out.println("-1");
    }

    static class Pair<T, R> {
        public T first;
        public R second;

        public Pair(T first, R second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public boolean equals(final Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
            final Pair<?, ?> pair = (Pair<?, ?>) o;
            return Objects.equals(first, pair.first) && Objects.equals(second, pair.second);
        }

        @Override
        public int hashCode() {
            return Objects.hash(first, second);
        }

        @Override
        public String toString() {
            return "Pair{" + "a=" + first + ", b=" + second + '}';
        }

        public T getFirst() {
            return first;
        }

        public R getSecond() {
            return second;
        }
    }

    static <T, R> Pair<T, R> make_pair(T a, R b) {
        return new Pair<>(a, b);
    }

    static class ArrayUtils {

        static void swap(int[] a, int i, int j) {
            int temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }

        static void swap(char[] a, int i, int j) {
            char temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }

        static void print(char[] a) {
            for (char c : a) {
                out.print(c);
            }
            out.println("");
        }

        static int[] reverse(int[] data) {
            int[] p = new int[data.length];
            for (int i = 0, j = data.length - 1; i < data.length; i++, j--) {
                p[i] = data[j];
            }
            return p;
        }

        static void prefixSum(long[] data) {
            for (int i = 1; i < data.length; i++) {
                data[i] += data[i - 1];
            }
        }

        static void prefixSum(int[] data) {
            for (int i = 1; i < data.length; i++) {
                data[i] += data[i - 1];
            }
        }

        static long[] reverse(long[] data) {
            long[] p = new long[data.length];
            for (int i = 0, j = data.length - 1; i < data.length; i++, j--) {
                p[i] = data[j];
            }
            return p;
        }

        static char[] reverse(char[] data) {
            char[] p = new char[data.length];
            for (int i = 0, j = data.length - 1; i < data.length; i++, j--) {
                p[i] = data[j];
            }
            return p;
        }

        static int[] MergeSort(int[] A) {
            if (A.length > 1) {
                int q = A.length / 2;
                int[] left = new int[q];
                int[] right = new int[A.length - q];
                System.arraycopy(A, 0, left, 0, q);
                System.arraycopy(A, q, right, 0, A.length - q);
                int[] left_sorted = MergeSort(left);
                int[] right_sorted = MergeSort(right);
                return Merge(left_sorted, right_sorted);
            } else {
                return A;
            }
        }

        static int[] Merge(int[] left, int[] right) {
            int[] A = new int[left.length + right.length];
            int i = 0;
            int j = 0;
            for (int k = 0; k < A.length; k++) {
                // To handle left becoming empty
                if (i == left.length && j < right.length) {
                    A[k] = right[j];
                    j++;
                    continue;
                }
                // To handle right becoming empty
                if (j == right.length && i < left.length) {
                    A[k] = left[i];
                    i++;
                    continue;
                }
                if (left[i] <= right[j]) {
                    A[k] = left[i];
                    i++;
                } else {
                    A[k] = right[j];
                    j++;
                }
            }
            return A;
        }

        static long[] MergeSort(long[] A) {
            if (A.length > 1) {
                int q = A.length / 2;
                long[] left = new long[q];
                long[] right = new long[A.length - q];
                System.arraycopy(A, 0, left, 0, q);
                System.arraycopy(A, q, right, 0, A.length - q);
                long[] left_sorted = MergeSort(left);
                long[] right_sorted = MergeSort(right);
                return Merge(left_sorted, right_sorted);
            } else {
                return A;
            }
        }

        static long[] Merge(long[] left, long[] right) {
            long[] A = new long[left.length + right.length];
            int i = 0;
            int j = 0;
            for (int k = 0; k < A.length; k++) {
                // To handle left becoming empty
                if (i == left.length && j < right.length) {
                    A[k] = right[j];
                    j++;
                    continue;
                }
                // To handle right becoming empty
                if (j == right.length && i < left.length) {
                    A[k] = left[i];
                    i++;
                    continue;
                }
                if (left[i] <= right[j]) {
                    A[k] = left[i];
                    i++;
                } else {
                    A[k] = right[j];
                    j++;
                }
            }
            return A;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 2048);
            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 long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readAllInts(int n) {
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = in.nextInt();
            }
            return p;
        }

        public int[] readAllInts(int n, int s) {
            int[] p = new int[n + s];
            for (int i = s; i < n + s; i++) {
                p[i] = in.nextInt();
            }
            return p;
        }

        public long[] readAllLongs(int n) {
            long[] p = new long[n];
            for (int i = 0; i < n; i++) {
                p[i] = in.nextLong();
            }
            return p;
        }

        public long[] readAllLongs(int n, int s) {
            long[] p = new long[n + s];
            for (int i = s; i < n + s; i++) {
                p[i] = in.nextLong();
            }
            return p;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    static void exit(int a) {
        out.close();
        err.close();
        System.exit(a);
    }

    static InputStream inputStream = System.in;
    static OutputStream outputStream = System.out;
    static OutputStream errStream = System.err;
    static InputReader in = new InputReader(inputStream);
    static PrintWriter out = new PrintWriter(outputStream);
    static PrintWriter err = new PrintWriter(errStream);
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

}


import java.util.*;
public class Main

{
    public static int getAns(String str,char ch,HashMap<String,Integer> map)
    {
        String temp=str+"|"+ch;
        if(str.length()==1)
         {
             if(str.charAt(0)==ch)return 0;
             else return 1;
         }
        if(map.containsKey(temp))return map.get(temp);
        int firstHalf=0,secondHalf=0;
        for(int i=1;i<=str.length();i++)
        {
            if(str.charAt(i-1)!=ch)
            {
                if(i>(str.length()/2))secondHalf++;
                else firstHalf++;
            }
        }
        ch=(char)(ch+1);

       int min= Math.min(firstHalf+getAns(str.substring(str.length()/2,str.length()),ch,map),secondHalf+getAns(str.substring(0,str.length()/2),ch,map));
       map.put(temp,min);
       return min;
    }
	public static void main(String[] args) {
		Scanner kb=new Scanner(System.in);
		int t=kb.nextInt();
		while(t-->0)
		{
		    int n=kb.nextInt();
		    String str=kb.next();
		    HashMap<String,Integer> map=new HashMap<>();
		    System.out.println(getAns(str,'a',map));
		}
	}
}


import java.util.*;
public class Main

{
    public static int getAns(String str,char ch)
    {
        if(str.length()==1)
         {
             if(str.charAt(0)==ch)return 0;
             else return 1;
         }
        int firstHalf=0,secondHalf=0;
        for(int i=1;i<=str.length();i++)
        {
            if(str.charAt(i-1)!=ch)
            {
                if(i>(str.length()/2))secondHalf++;
                else firstHalf++;
            }
        }
        ch=(char)(ch+1);
        return Math.min(firstHalf+getAns(str.substring(str.length()/2,str.length()),ch),secondHalf+getAns(str.substring(0,str.length()/2),ch));
    }
	public static void main(String[] args) {
		Scanner kb=new Scanner(System.in);
		int t=kb.nextInt();
		while(t-->0)
		{
		    int n=kb.nextInt();
		    String str=kb.next();
		    System.out.println(getAns(str,'a'));
		}
	}
}


import java.util.*;
public class Main{
    public static int min(String s,int start,int end,char c){
        if(start==end){
            if(s.charAt(start)==c) return 0;
            else return 1;
        }
        int mid=(start+end)/2;
        char d=(char)(c+1);
        int cnt1=(end-start+1)/2;
        int cnt2=cnt1;
        for(int i=start;i<=mid;i++){
            if(s.charAt(i)==c) cnt1--;
        }
        for(int i=mid+1;i<=end;i++){
            if(s.charAt(i)==c) cnt2--;
        }
        //System.out.println(cnt1+" "+cnt2);
        int a=min(s,start,mid,d);
        int b=min(s,mid+1,end,d);
        return Math.min(cnt2+a,cnt1+b);
    }
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            String s=sc.next();
            System.out.println(min(s,0,n-1,'a'));
        }
    }
}


import java.util.*;
public class Main{
    public static int min(String s,int start,int end,char c){
        if(start==end){
            if(s.charAt(start)==c) return 0;
            else return 1;
        }
        int mid=(start+end)/2;
        char d=(char)(c+1);
        int a=min(s,start,mid,d);
        int b=min(s,mid+1,end,d);
        int cnt1=(end-start+1)/2;
        int cnt2=cnt1;
        for(int i=start;i<=mid;i++){
            if(s.charAt(i)==c) cnt1--;
        }
        for(int i=mid+1,i<=end;i++){
            if(s.charAt(i)==c) cnt2--;
        }
        return Math.min(cnt1+a,cnt2+b);
    }
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            String s=sc.next();
            System.out.println(min(s,0,n-1,'a'));
        }
    }
}


import java.util.*;
public class Main{
    public static int min(String s,int start,int end,char c){
        if(start==end){
            if(s.charAt(start)==c) return 0;
            else return 1;
        }
        int mid=(start+end)/2;
        char d=(char)(c+1);
        int a=min(s,start,mid,d);
        int b=min(s,mid+1,end,d);
        int cnt1=(end-start+1)/2;
        int cnt2=cnt1;
        for(int i=start;i<=mid;i++){
            if(s.charAt(i)==c) cnt1--;
        }
        for(int i=mid+1;i<=end;i++){
            if(s.charAt(i)==c) cnt2--;
        }
        return Math.min(cnt1+a,cnt2+b);
    }
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            String s=sc.next();
            System.out.println(min(s,0,n-1,'a'));
        }
    }
}


import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Scanner;

public class Div656 {
	static Scanner sc =new Scanner(System.in);
	static PrintWriter out =new PrintWriter(System.out);

	public static void ThreePairwiseMaximums() {
		int t=sc.nextInt();
		outer:for(int o=0;o<t;o++) {
			int x=sc.nextInt();
			int y=sc.nextInt();
			int z=sc.nextInt();
			int []n= {x,y,z};
			int a=0;
			int b=0;
			int c=0;
			for(int i=0;i<3;i++) {
				for(int j=0;j<3;j++) {
					for(int k=0;k<3;k++) {
						a=n[i];
						b=n[j];
						c=n[k];
						if(x==Math.max(a,b)&&y==Math.max(a, c)&&z==Math.max(b, c)) {
							System.out.println("YES");
							System.out.println(a+" "+b+" "+c);
							continue outer;
						}
					}
				}
			}
			System.out.println("NO");
		}
	}

	public static void RestorethePermutationyMerger() {
		int t=sc.nextInt();
		for(int o=0;o<t;o++) {
			int n=sc.nextInt();
			LinkedHashSet<Integer>s =new LinkedHashSet<Integer>();
			for(int i=0;i<2*n;i++) {
				s.add(sc.nextInt());
			}
			for(Integer a:s) {
				System.out.print(a+" ");
			}
			System.out.println();

		}
	}

	public static int aGoodStringRec(String s,int l,int r,char c,int[][]ch,int[]counterCh,int temp){
		if(l==r&&s.charAt(l)==c)return 0;
		else if(l==r&&s.charAt(l)!=c)return 1;
		//int x=temp;
		//temp/=2;
		//(temp/2)-ch[(l+r)/2][c-97]
		int y=0;
		if(l>0) {
			y=ch[l-1][c-97];
			///System.out.println("y "+y+"  "+c);

		}
		int fH=(temp/2)-(ch[(l+r)/2][c-97]-y);
		int sH=(temp/2)-(ch[r][c-97]-ch[(l+r)/2][c-97]);
		int mid=(l+r)/2;
		//System.out.println("fH "+fH+"  "+s.substring(mid+1, r+1)+"   "+c+"  "+(int)(mid+1)+"   "+r);
		int FT=fH+aGoodStringRec(s,mid+1,r,(char) (c+1),ch,counterCh,temp/2);
		//System.out.println(FT);
		//System.out.println("sH "+sH+"   "+s.substring(l,mid+1)+"   "+c+"   "+l+"   "+mid);
		int ST=sH+aGoodStringRec(s,l,mid,(char) (c+1),ch,counterCh,temp/2);
		//System.out.println(ST);
		return Math.min(FT,ST);

	}

	public static void aGoodString(){
		int t=sc.nextInt();
		sc.nextLine();
		for(int o=0;o<t;o++) {
			int n=sc.nextInt();
			sc.nextLine();
			String s=sc.nextLine();
			int [][]ch=new int[n][26];
			int []counterCh=new int[26];
			for(int i=0;i<s.length();i++) {
				counterCh[s.charAt(i)-97]++;
				for(int j=0;j<26;j++) {
					//System.out.println(j);
					ch[i][j]=counterCh[j];
				}
			}
		//	for(int i=0;i<n;i++)
			//	System.out.println(Arrays.toString(ch[i]));
//			char c='a';
//			int temp=n;
//			int l=0;
//			int r=n-1;
//			int count=0;
//			while(temp>1) {
//				int mid=(l+r)/2;
//				//System.out.println(l+"  "+r+"   "+mid);
//				//System.out.println(+" "+ch[r][c-97]);
//				if(ch[mid][c-97] >ch[r][c-97]-ch[mid][c-97]) {
//				//	System.out.println(count+"  "+c+"   "+temp);
//					count+=(temp/2)-ch[(l+r)/2][c-97];
//					l=mid;
//				}
//				else {
//					count+=(temp/2)-ch[r][c-97];
//					r=mid;
//
//				}
//				//int x=temp/2;
//			//	count+=((temp/2)-Math.max(ch[(temp/2)-1][c-97], ch[temp-1][c-97]));
//
//				temp/=2;
//
//				c++;
//			}
//			//System.out.println(c+"  "+l+"  "+r);
//			if(s.charAt(l)!=c&&s.charAt(r)!=c)count++;
//			System.out.println(count);

			System.out.println(aGoodStringRec(s,0,n-1,'a',ch,counterCh,n));

		}
	}

	public static void MakeItGood() {
		int t=sc.nextInt();
		for(int o=0;o<t;o++) {
			int n=sc.nextInt();
			int a[]=new int[n];
			Integer b[]=new Integer[n];
			HashMap<Integer,Integer>h=new HashMap<Integer,Integer>();
			for(int i=0;i<n;i++){
				a[i]=sc.nextInt();
				b[i]=a[i];
				if(h.get(a[i])==null)h.put(a[i], 1);
				else h.put(a[i],h.get(a[i])+1);
			}
			if(n==1) {
				System.out.println(0);
				continue;
			}
			Arrays.sort(b);

			int l=0;int r=n-1;
			int m=0;
			int i=0;
			boolean f=true;
			while(l<r) {
				if(a[r]==b[i]) {
					h.put(a[r], h.get(a[r])-1);

					r--;
					i++;
				}
				else if(a[l]==b[i]&&f) {
					h.put(a[l], h.get(a[l])-1);

					l++;
					i++;
				}
				else if(a[l]==b[i]&&!f) {
					h.put(a[l], h.get(a[l])-1);

					m=l;
					f=true;
					i++;
					l++;
				}
				else {
					h.put(a[l], h.get(a[l])-1);
					f=false;
					l++;
				}
			}
            //if(!f)m+=(l);
			System.out.println(m);

		}
	}

	public static void MakeItGood2() {
		int t=sc.nextInt();
		for(int o=0;o<t;o++) {
			int n=sc.nextInt();
			int a[]=new int[n];
			Integer b[]=new Integer[n];
			HashMap<Integer,Integer>h=new HashMap<Integer,Integer>();
			for(int i=0;i<n;i++){
				a[i]=sc.nextInt();
				b[i]=a[i];
				if(h.get(a[i])==null)h.put(a[i], 1);
				else h.put(a[i],h.get(a[i])+1);
			}
			if(n==1) {
				System.out.println(0);
				continue;
			}
			Arrays.sort(b);

			int l=0;int r=n-1;
			int m=0;
			//System.out.println(h);
			for(int i=0;i<b.length&&l<r;i++) {
				if(h.get(b[i])==null||h.get(b[i])==0)continue;
				if(a[l]==b[i]) {
					h.put(b[i],h.get(b[i])-1);
					l++;
				}
				else if(a[r]==b[i]) {
					h.put(b[i],h.get(b[i])-1);

					r--;
				}
				else {
					h.put(a[l],h.get(a[l])-1);
					for(int j=l+1;j<r;j++) {
						h.put(a[j],h.get(a[j])-1);

						if(a[j]==b[i]) {
							m=j;
							l=j+1;
							break;
						}

					}
				}
				//System.out.println(h);
			}

			System.out.println(m);

		}
	}

	public static void main(String[] args) {
		//ThreePairwiseMaximums();
	//	RestorethePermutationyMerger();
		aGoodString();
		//MakeItGood2();

	}

}


import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Scanner;

public class Div656 {
	static Scanner sc =new Scanner(System.in);
	static PrintWriter out =new PrintWriter(System.out);

	public static void ThreePairwiseMaximums() {
		int t=sc.nextInt();
		outer:for(int o=0;o<t;o++) {
			int x=sc.nextInt();
			int y=sc.nextInt();
			int z=sc.nextInt();
			int []n= {x,y,z};
			int a=0;
			int b=0;
			int c=0;
			for(int i=0;i<3;i++) {
				for(int j=0;j<3;j++) {
					for(int k=0;k<3;k++) {
						a=n[i];
						b=n[j];
						c=n[k];
						if(x==Math.max(a,b)&&y==Math.max(a, c)&&z==Math.max(b, c)) {
							System.out.println("YES");
							System.out.println(a+" "+b+" "+c);
							continue outer;
						}
					}
				}
			}
			System.out.println("NO");
		}
	}

	public static void RestorethePermutationyMerger() {
		int t=sc.nextInt();
		for(int o=0;o<t;o++) {
			int n=sc.nextInt();
			LinkedHashSet<Integer>s =new LinkedHashSet<Integer>();
			for(int i=0;i<2*n;i++) {
				s.add(sc.nextInt());
			}
			for(Integer a:s) {
				System.out.print(a+" ");
			}
			System.out.println();

		}
	}

	public static int aGoodStringRec(String s,int l,int r,char c,int[][]ch,int[]counterCh,int temp){
		if(l==r&&s.charAt(l)==c)return 0;
		else if(l==r&&s.charAt(l)!=c)return 1;
		//int x=temp;
		//temp/=2;
		//(temp/2)-ch[(l+r)/2][c-97]
		int y=0;
		if(l>0)y=ch[l-1][c-97];
		int fH=(temp/2)-(ch[(l+r)/2][c-97]-y);
		int sH=(temp/2)-(ch[r][c-97]-ch[(l+r)/2][c-97]-y);
		int mid=(l+r)/2;
		//System.out.println("fH "+fH+"  "+l+"   "+mid+"   "+c);
		int FT=fH+aGoodStringRec(s,mid+1,r,(char) (c+1),ch,counterCh,temp/2);
		//System.out.println(FT);
		//System.out.println("sH "+sH+"   "+mid+1+"   "+r+"   "+c);
		int ST=sH+aGoodStringRec(s,l,mid,(char) (c+1),ch,counterCh,temp/2);
		//System.out.println(ST);
		return Math.min(FT,ST);

	}

	public static void aGoodString(){
		int t=sc.nextInt();
		sc.nextLine();
		for(int o=0;o<t;o++) {
			int n=sc.nextInt();
			sc.nextLine();
			String s=sc.nextLine();
			int [][]ch=new int[n][26];
			int []counterCh=new int[26];
			for(int i=0;i<s.length();i++) {
				counterCh[s.charAt(i)-97]++;
				for(int j=0;j<26;j++) {
					//System.out.println(j);
					ch[i][j]=counterCh[j];
				}
			}
		//	for(int i=0;i<n;i++)
			//	System.out.println(Arrays.toString(ch[i]));
//			char c='a';
//			int temp=n;
//			int l=0;
//			int r=n-1;
//			int count=0;
//			while(temp>1) {
//				int mid=(l+r)/2;
//				//System.out.println(l+"  "+r+"   "+mid);
//				//System.out.println(+" "+ch[r][c-97]);
//				if(ch[mid][c-97] >ch[r][c-97]-ch[mid][c-97]) {
//				//	System.out.println(count+"  "+c+"   "+temp);
//					count+=(temp/2)-ch[(l+r)/2][c-97];
//					l=mid;
//				}
//				else {
//					count+=(temp/2)-ch[r][c-97];
//					r=mid;
//
//				}
//				//int x=temp/2;
//			//	count+=((temp/2)-Math.max(ch[(temp/2)-1][c-97], ch[temp-1][c-97]));
//
//				temp/=2;
//
//				c++;
//			}
//			//System.out.println(c+"  "+l+"  "+r);
//			if(s.charAt(l)!=c&&s.charAt(r)!=c)count++;
//			System.out.println(count);

			System.out.println(aGoodStringRec(s,0,n-1,'a',ch,counterCh,n));

		}
	}

	public static void MakeItGood() {
		int t=sc.nextInt();
		for(int o=0;o<t;o++) {
			int n=sc.nextInt();
			int a[]=new int[n];
			Integer b[]=new Integer[n];
			HashMap<Integer,Integer>h=new HashMap<Integer,Integer>();
			for(int i=0;i<n;i++){
				a[i]=sc.nextInt();
				b[i]=a[i];
				if(h.get(a[i])==null)h.put(a[i], 1);
				else h.put(a[i],h.get(a[i])+1);
			}
			if(n==1) {
				System.out.println(0);
				continue;
			}
			Arrays.sort(b);

			int l=0;int r=n-1;
			int m=0;
			int i=0;
			boolean f=true;
			while(l<r) {
				if(a[r]==b[i]) {
					h.put(a[r], h.get(a[r])-1);

					r--;
					i++;
				}
				else if(a[l]==b[i]&&f) {
					h.put(a[l], h.get(a[l])-1);

					l++;
					i++;
				}
				else if(a[l]==b[i]&&!f) {
					h.put(a[l], h.get(a[l])-1);

					m=l;
					f=true;
					i++;
					l++;
				}
				else {
					h.put(a[l], h.get(a[l])-1);
					f=false;
					l++;
				}
			}
            //if(!f)m+=(l);
			System.out.println(m);

		}
	}

	public static void MakeItGood2() {
		int t=sc.nextInt();
		for(int o=0;o<t;o++) {
			int n=sc.nextInt();
			int a[]=new int[n];
			Integer b[]=new Integer[n];
			HashMap<Integer,Integer>h=new HashMap<Integer,Integer>();
			for(int i=0;i<n;i++){
				a[i]=sc.nextInt();
				b[i]=a[i];
				if(h.get(a[i])==null)h.put(a[i], 1);
				else h.put(a[i],h.get(a[i])+1);
			}
			if(n==1) {
				System.out.println(0);
				continue;
			}
			Arrays.sort(b);

			int l=0;int r=n-1;
			int m=0;
			//System.out.println(h);
			for(int i=0;i<b.length&&l<r;i++) {
				if(h.get(b[i])==null||h.get(b[i])==0)continue;
				if(a[l]==b[i]) {
					h.put(b[i],h.get(b[i])-1);
					l++;
				}
				else if(a[r]==b[i]) {
					h.put(b[i],h.get(b[i])-1);

					r--;
				}
				else {
					h.put(a[l],h.get(a[l])-1);
					for(int j=l+1;j<r;j++) {
						h.put(a[j],h.get(a[j])-1);

						if(a[j]==b[i]) {
							m=j;
							l=j+1;
							break;
						}

					}
				}
				//System.out.println(h);
			}

			System.out.println(m);

		}
	}

	public static void main(String[] args) {
		//ThreePairwiseMaximums();
	//	RestorethePermutationyMerger();
		aGoodString();
		//MakeItGood2();

	}

}