#include <bits/stdc++.h>
using namespace std;
#define SC scanf
#define PF printf
#define ull unsigned long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sort_a(a) sort(a.begin(),a.end());
#define sort_d(a) sort(a.rbegin(),a.rend());
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define rev(s) reverse(s.begin(),s.end())
#define P(ok) cout << (ok ? "YES\n": "NO\n")
#define __Heart__ ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll> PII;
const int sz = 1e5 + 5 ;
int dp[sz][5] , n ;
string s ;
vector < string > allVowel ;
map < pair < char , char > , int > costAtoB ;
void preCalc(){
string v = "aeiou" ;
do {
allVowel.pb(v) ;
} while(next_permutation(v.begin() , v.end())) ;
}
void costToTransform() {
string v = "aeiou" ;
for(int i = 0 ; i < 5 ; i++) {
for(int j = 0 ; j < 5 ; j++){
int cost = (j - i + 5) % 5;
costAtoB[{v[i] , v[j]}] = cost ;
}
}
// for(int i = 0 ; i < 5 ; i++){
// for(int j = 0 ; j < 5 ; j++) {
// cout <<v[i] << " " << v[j] << " --> " << costAtoB[{v[i], v[j]}] << endl ;
// }
// }
}
int heart(int i , int j , const string& curState) {
if(i == n) return 0 ;
if(dp[i][j] != -1) return dp[i][j] ;
int transformCost = costAtoB[{s[i], curState[j]}];
if(j < 4) {
dp[i][j] = min(transformCost + heart(i + 1 , j , curState) , transformCost + heart(i + 1 , j + 1 , curState)) ;
}
else {
dp[i][j] = transformCost + heart(i + 1 , j , curState) ;
}
return dp[i][j];
}
void solve()
{
cin >> n >> s ;
int Ans = INT_MAX ;
for(auto curState : allVowel){
for(int i = 0 ; i <= n ; i++) for(int j = 0 ; j < 5 ; j++) dp[i][j] = -1 ;
Ans = min(Ans , heart(0 , 0 , curState)) ;
// cout << curState << " " << Ans << endl ;
}
cout << Ans << "\n" ;
}
int main()
{
__Heart__
preCalc() ;
costToTransform() ;
int t ; cin >> t ; while(t--) solve() ;
}