#include <bits/stdc++.h>
using namespace std;
// #include "debug.h"
template <const int SZ>
struct numb {
static constexpr int M = SZ;
int pc = 0;
array<int, M> primes, lpf;
bitset<M> isPrime;
constexpr numb() {
for (int i = 2; i < M; ++i) {
if (!lpf[i]) {
primes[pc++] = i;
lpf[i] = i;
isPrime[i] = 1;
}
for (int j = 0;
j < pc && 1LL * i * primes[j] < M && primes[j] <= lpf[i]; j++)
lpf[i * primes[j]] = primes[j];
}
}
pair<int, array<int, 30>> pfact(int V) {
array<int, 30> ret;
int sz = 0;
for (int p = lpf[V], cnt = 0; V > 1; p = lpf[V], cnt = 0) {
while (V % p == 0)
V /= p;
ret[sz++] = p;
}
return {sz, ret};
}
pair<int, array<pair<int, int>, 30>> pfact_with_frq(int V) {
array<pair<int, int>, 30> ret;
int sz = 0;
for (int p = lpf[V], cnt = 0; V > 1; p = lpf[V], cnt = 0) {
while (V % p == 0)
V /= p, ++cnt;
ret[sz++] = {p, cnt};
}
return {sz, ret};
}
};
const int N = 2e3 + 10;
numb<N> nb;
const int inf = 1e9;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> cnt(3);
for (int i = 0; i < n; ++i) {
++cnt[s[i] - 'a'];
}
int ans = inf;
for (int i = 0; i <= nb.pc; ++i) {
for (int j = 0; j <= nb.pc; ++j) {
int p1 = (i ? nb.primes[i - 1] : 0);
int p2 = (j ? nb.primes[j - 1] : 0);
int p3 = n - (p1 + p2);
if (p3 < 0 || (p3 > 0 && !nb.isPrime[p3])) {
continue;
}
int ansH = 0;
ansH += max(0, p1 - cnt[0]);
ansH += max(0, p2 - cnt[1]);
ansH += max(0, p3 - cnt[2]);
ans = min(ansH, ans);
}
}
cout << ans << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tc = 1;
cin >> tc;
while (tc--) {
solve();
}
}