#include <bits/stdc++.h>
using namespace std;
const long long M = 2e5 + 10, MOD = 1000000007;
typedef long long ll;
int cost[26][26];
vector<string> all;
void precal() {
string vowel = "aeiou";
for (int i = 0; i < (int)vowel.size(); i++) {
int l = i;
int cnt = 0;
while (cnt < 5) {
cost[vowel[i] - 'a'][vowel[l] - 'a'] = cnt;
l++;
cnt++;
if (l == 5) l = 0;
}
}
all.push_back(vowel);
while (next_permutation(vowel.begin(), vowel.end())) {
all.push_back(vowel);
}
}
int solve(int idx, int p_idx, string &s, string &p, vector<vector<int>> &memo) {
if (idx == 0) return 0;
if (memo[idx][p_idx] != -1) return memo[idx][p_idx]; // Use memoized value
int pro = cost[s[idx - 1] - 'a'][p[p_idx] - 'a'];
int option1 = solve(idx - 1, p_idx, s, p, memo) + pro;
int option2 = INT_MAX;
if (p_idx > 0) {
option2 = solve(idx, p_idx - 1, s, p, memo);
}
return memo[idx][p_idx] = min(option1, option2);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
precal();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
int mx = INT_MAX;
for (auto &it : all) {
string p = it;
vector<vector<int>> memo(n + 1, vector<int>(5, -1));
for (int i = 0; i < 5; i++) {
mx = min(mx, solve(n, i, s, p, memo));
}
}
cout << mx << "\n";
}
return 0;
}