#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
// Function to check if a number is prime
bool isPrime(int n) {
if (n <= 1) return false;
for (int i = 2; i <= sqrt(n); ++i) {
if (n % i == 0) return false;
}
return true;
}
// Function to find the nearest prime number greater than or equal to n
int nearestPrime(int n) {
while (!isPrime(n)) {
++n;
}
return n;
}
// Function to compute the minimum number of operations to make the string beautiful
int minOperationsToMakeBeautiful(int N, const string& S) {
// Count occurrences of 'a', 'b', and 'c'
int count_a = 0, count_b = 0, count_c = 0;
for (char ch : S) {
if (ch == 'a') count_a++;
else if (ch == 'b') count_b++;
else if (ch == 'c') count_c++;
}
// Find the nearest prime numbers greater than or equal to the counts
int prime_a = nearestPrime(count_a);
int prime_b = nearestPrime(count_b);
int prime_c = nearestPrime(count_c);
// Calculate the number of operations required to make each count a prime number
int operations = abs(prime_a - count_a) + abs(prime_b - count_b) + abs(prime_c - count_c);
return operations;
}
int main() {
int T; // Number of test cases
cin >> T;
while (T--) {
int N; // Length of the string
cin >> N;
string S; // The string S
cin >> S;
// Get the minimum number of operations for each test case
cout << minOperationsToMakeBeautiful(N, S) << endl;
}
return 0;
}