description: A string s of length n, consisting of lowercase letters of the English alphabet, is given.
  
  You must choose some number k between 0 and n. Then, you select k characters of s and permute them however you want. In this process, the positions of the other n-k characters remain unchanged. You have to perform this operation exactly once.
  
  For example, if s="andrea", you can choose the k=4 characters "a_d_ea" and permute them into "d_e_aa" so that after the operation the string becomes "dneraa".
  
  Determine the minimum k so that it is possible to sort s alphabetically (that is, after the operation its characters appear in alphabetical order).
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
  
  The first line of each test case contains one integer n (1 ≤ n ≤ 40) — the length of the string.
  
  The second line of each test case contains the string s. It is guaranteed that s contains only lowercase letters of the English alphabet.
  
  Output
  
  For each test case, output the minimum k that allows you to obtain a string sorted alphabetically, through the operation described above.
  
  Example
  
  Input
  
  
  4
  3
  lol
  10
  codeforces
  5
  aaaaa
  4
  dcba
  
  
  Output
  
  
  2
  6
  0
  4
  
  Note
  
  In the first test case, we can choose the k=2 characters "_ol" and rearrange them as "_lo" (so the resulting string is "llo"). It is not possible to sort the string choosing strictly less than 2 characters.
  
  In the second test case, one possible way to sort s is to consider the k=6 characters "_o__force_" and rearrange them as "_c__efoor_" (so the resulting string is "ccdeefoors"). One can show that it is not possible to sort the string choosing strictly less than 6 characters.
  
  In the third test case, string s is already sorted (so we can choose k=0 characters).
  
  In the fourth test case, we can choose all k=4 characters "dcba" and reverse the whole string (so the resulting string is "abcd").
solution: import java.util.*;import java.io.*;import java.math.*;
  public class CF1552A
  {
      static boolean memory = true;
      static long mod = 998244353;
      static long MOD = 1000000007; 
      
      static void ruffleSort(int[] a) {
          int n = a.length;
          ArrayList<Integer> lst = new ArrayList<>();
          for(int i : a)
              lst.add(i);
          Collections.sort(lst);
          for(int i = 0; i < n; i++)
              a[i] = lst.get(i);
      }
  
      static void ruffleSort(long[] a) {
          int n = a.length; 
          ArrayList<Long> lst = new ArrayList<>();
          for(long i : a)
              lst.add(i);
          Collections.sort(lst);
          for(int i = 0; i < n; i++)
              a[i] = lst.get(i);
      }
  
      public static void process()throws IOException
      {
          int n = ni();
          char[] ch = ns().toCharArray();
          char[] temp = Arrays.copyOf(ch, n);
          Arrays.sort(temp);
          int ans = 0;
          for(int i = 0; i < n; i++){
              if(ch[i] != temp[i])
                  ans++;
          }
          pn(ans);
      }
     
      static AnotherReader sc;
      static PrintWriter out;
  
      public static void main(String[] args) throws Exception{
          if(memory)new Thread(null, new Runnable() {public void run(){try{new CF1552A().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "1", 1 << 32).start();
          else new CF1552A().run();
      }
  
      void run()throws Exception
      {
          boolean oj = System.getProperty("ONLINE_JUDGE") != null;
          if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
          else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
          long s = System.currentTimeMillis();
          int t=1;
          t=ni();
          //int k = t;
          while(t-->0) {/*p("Case #"+ (k-t) + ": ")*/;process();}
          out.flush();
          System.err.println(System.currentTimeMillis()-s+"ms");
          out.close();
      }
  
      static long power(long k, long c, long mod){
          long y = 1;
          while(c > 0){
              if(c%2 == 1)
                  y = y * k % mod;
              c = c/2;
              k = k * k % mod;
          }
          return y;
      }
  
      static int power(int x, int y, int p){ 
          int res = 1;
          x = x % p;
          while (y > 0) {
              if (y % 2 == 1)
                  res = (res * x) % p;
              y = y >> 1;
              x = (x * x) % p;
          }
          return res;
      }
  
      static int log2(int N)
      {
          int result = (int)(Math.log(N) / Math.log(2));
          return result;
      }
  
   
      static void pn(Object o){out.println(o);}
      static void pn(int[] a){for(int i : a)out.print(i+" ");pn("");}
      static void pn(long[] a){for(long i : a)out.print(i+" ");pn("");}
      static void p(Object o){out.print(o);}
      static void YES(){out.println("YES");}
      static void NO(){out.println("NO");}
      static void yes(){out.println("yes");}
      static void no(){out.println("no");}
      static void p(int[] a){for(int i : a)out.print(i+" ");}
      static void p(long[] a){for(long i : a)out.print(i+" ");}
      static void pni(Object o){out.println(o);out.flush();}
      static int ni()throws IOException{return sc.nextInt();}
      static long nl()throws IOException{return sc.nextLong();}
      static double nd()throws IOException{return sc.nextDouble();}
      static String nln()throws IOException{return sc.nextLine();}
      static String ns()throws IOException{return sc.next();}
      static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
      static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
      static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
      static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
      static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
      
  /////////////////////////////////////////////////////////////////////////////////////////////////////////
   
      static class AnotherReader{BufferedReader br; StringTokenizer st;
      AnotherReader()throws FileNotFoundException{
      br=new BufferedReader(new InputStreamReader(System.in));}
      AnotherReader(int a)throws FileNotFoundException{
      br = new BufferedReader(new FileReader("input.txt"));}
      String next()throws IOException{
      while (st == null || !st.hasMoreElements()) {try{
      st = new StringTokenizer(br.readLine());}
      catch (IOException  e){ e.printStackTrace(); }}
      return st.nextToken(); } int nextInt() throws IOException{
      return Integer.parseInt(next());}
      long nextLong() throws IOException
      {return Long.parseLong(next());}
      double nextDouble()throws IOException { return Double.parseDouble(next()); }
      String nextLine() throws IOException{ String str = ""; try{
      str = br.readLine();} catch (IOException e){
      e.printStackTrace();} return str;}}
  
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  }