for _ in range(int(input())):
   n = input()
   s = list(map(ord, str(input())))
   A = 97
   m = 0
   mid = len(s)//2
   while mid>=1:
      f_half = s[:mid].count(A)
      s_half = s[mid:].count(A)
      if f_half > s_half:  
         m = m + (mid - f_half)
         s = s[mid:]
      elif f_half == s_half:
         if max(s[mid:]) - min(s[mid:]) < max(s[:mid])-min(s[:mid]):
            m = m + (mid - f_half)
            s = s[mid:]
         else:
            m = m + (mid - s_half)
            s = s[:mid]
      else: 
         m = m + (mid - s_half)
         s = s[:mid]
      A+=1
      mid//=2
      
   if s[0]!=A: print(m+1)
   else: print(m)
