#include <bits/stdc++.h>
struct fcts {
  static std::pair<std::set<long long>, std::vector<long long>> buildsieve(
      unsigned long long n);
  static bool ArePermuted(std::string s1, std::string s2);
  static void RotateSubstr(std::string& s, int j, int k);
  static bool IsSquare(long long n);
  static bool IsPrime(long long n);
};
std::pair<std::set<long long>, std::vector<long long>> fcts::buildsieve(
    unsigned long long n) {
  std::vector<long long> first_div(n, 0);
  std::set<long long> primes;
  for (long long i = 2; i < n; i++) {
    if (first_div[i] == 0) {
      primes.insert(i);
      for (long long j = i; j < n; j += i) {
        first_div[j] = i;
      }
    }
  }
  return std::make_pair(primes, first_div);
}
bool fcts::ArePermuted(std::string s1, std::string s2) {
  sort(s1.begin(), s1.end());
  sort(s2.begin(), s2.end());
  for (int i = 0; i < s1.size(); i++)
    if (s1[i] != s2[i]) return false;
  return true;
}
void fcts::RotateSubstr(std::string& s, int j, int k) {
  char temp = s[k];
  for (int i = k; i > j; i--) {
    s[i] = s[i - 1];
  }
  s[j] = temp;
}
bool fcts::IsSquare(long long n) {
  long long i = 0, j = n / 2, m;
  while (i < j) {
    m = (i + j) / 2;
    if (m * m == n) {
      return true;
    } else if (m * m > n) {
      j = m - 1;
    } else {
      i = m + 1;
    }
  }
  m = (i + j) / 2;
  return (m * m == n);
}
bool fcts::IsPrime(long long n) {
  if (IsSquare(n)) {
    return false;
  }
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
template <class T = unsigned int>
class digit {
 public:
  std::vector<T> dig;
  T num;
  digit(T);
  digit<T> operator+(digit<T> m);
  digit<T> operator-(digit<T> m);
  digit<T> operator*(digit<T> m);
};
template <class T>
digit<T>::digit(T n) {
  num = n;
  dig = std::vector<T>((int)(log10(n)) + 1);
  while (n > 0) {
    dig[(int)log10(n)] = n / ((T)pow(10, (int)log10(n)));
    n -= dig[(int)log10(n)] * ((T)pow(10, (int)log10(n)));
  }
}
template <class T>
digit<T> digit<T>::operator+(digit<T> m) {
  return digit<T>(m.num + this->num);
}
template <class T>
digit<T> digit<T>::operator-(digit<T> m) {
  return digit<T>(-m.num + this->num);
}
template <class T>
digit<T> digit<T>::operator*(digit<T> m) {
  return digit<T>(m.num * this->num);
}
template <class T>
class DiGraph {
 public:
  std::unordered_map<T, std::vector<T>> adj;
  void AddNode(T n1);
  void Connect(T n1, T n2);
  bool IsConnected(T n1, T n2);
  std::pair<std::unordered_map<T, int>, std::unordered_map<T, T>> BFS(T start);
};
template <class T>
class Undirected_Graph : public DiGraph<T> {
 public:
  void Connect(T n1, T n2);
};
template <class T>
void DiGraph<T>::AddNode(T n1) {
  if (adj.find(n1) == adj.end()) {
    adj[n1] = std::vector<T>(0, NULL);
  }
}
template <class T>
void DiGraph<T>::Connect(T n1, T n2) {
  adj[n1].push_back(n2);
}
template <class T>
void Undirected_Graph<T>::Connect(T n1, T n2) {
  DiGraph<T>::adj[n1].push_back(n2);
  DiGraph<T>::adj[n2].push_back(n1);
}
template <class T>
bool DiGraph<T>::IsConnected(T n1, T n2) {
  return (std::find(adj[n1].begin(), adj[n1].end(), n2) != adj[n1].end()) ||
         (std::find(adj[n2].begin(), adj[n2].end(), n1) != adj[n2].end());
}
template <class T>
std::pair<std::unordered_map<T, int>, std::unordered_map<T, T>> DiGraph<T>::BFS(
    T start) {
  T current;
  std::unordered_map<T, T> parent = {{start, NULL}};
  std::unordered_map<T, int> distance = {{start, 0}};
  std::queue<T> Q;
  Q.push(start);
  while (!Q.empty()) {
    current = Q.front();
    Q.pop();
    for (T u : adj[current]) {
      if (distance.find(u) == distance.end()) {
        distance[u] = distance[current] + 1;
        parent[u] = current;
        Q.push(u);
      }
    }
  }
  return std::make_pair(distance, parent);
}
template <class T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
  for (auto i : v) {
    out << i << " ";
  }
  return out;
}
template <class T>
std::ostream& operator<<(std::ostream& out, const std::set<T>& s) {
  for (auto i : s) {
    out << i << " ";
  }
  return out;
}
template <class T, class T1>
std::ostream& operator<<(std::ostream& out, const std::map<T, T1>& m) {
  for (auto i : m) {
    out << i.first << " : " << i.second << std::endl;
  }
  return out;
}
template <class T, class T1>
std::ostream& operator<<(std::ostream& out,
                         const std::unordered_map<T, T1>& m) {
  for (auto i : m) {
    out << i.first << " : " << i.second << std::endl;
  }
  return out;
}
template <class T>
std::ostream& operator<<(std::ostream& out, const DiGraph<T>& g) {
  out << g.adj;
  return out;
}
int main() {
  long long t, n, h1, h2, mvs, nxt1, nxt2, offset;
  char c;
  std::cin >> t;
  std::string a;
  while (t--) {
    c = 'a';
    std::cin >> n >> a;
    std::vector<bool> tbc(n, false);
    offset = 0;
    mvs = 0;
    while (n > 1) {
      h1 = 0;
      h2 = 0;
      nxt1 = 0;
      nxt2 = 0;
      for (long long i = 0; i < n / 2; i++) {
        if (a[i] != c) {
          h1++;
          tbc[i + offset] = true;
          if (a[i] == c + 1) {
            nxt1++;
          }
        } else {
          tbc[i + offset] = false;
        }
      }
      for (long long i = n / 2; i < n; i++) {
        if (a[i] != c) {
          h2++;
          tbc[i + offset] = true;
          if (a[i] == c + 1) {
            nxt2++;
          }
        } else {
          tbc[i + offset] = false;
        }
      }
      c++;
      if (h1 < h2 || (h1 == h2 && nxt1 < nxt2)) {
        a = a.substr((n / 2), n);
        offset += n / 2;
      } else {
        a = a.substr(0, (n / 2));
      }
      n /= 2;
    }
    if (a[0] == c) {
      tbc[offset] = false;
    } else {
      tbc[offset] = true;
    }
    for (auto i : tbc) {
      if (i) {
        mvs++;
      }
    }
    std::cout << mvs << '\n';
  }
}
