#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <map>
#include <queue>
#include <cmath>
using std::vector;
using std::cin;
using std::cout;

using namespace std;

int dominantA (string k, char a, int left, int right) {

    int score = 0;
    for (int i = left; i <= right; i++) {
        if (k[i] != a)
            score++;
    }
    return score;
}

long dp [20][131075];

long help (long left, long right, string k, long cnt[][26], long depth) {

    int a = 'a' + depth;
    if (a > 'z' || depth > 18 || left > right || left < 0 || right >= k.size())
        return (int)10e8;

    if (left == right) {
        if (k[left] == a)
            return 0;
        else
            return 1;
    }
    long mid = ((long)left + right + 1) / 2;
    mid--;
    long leftCost = dominantA(k, a, left, mid);
    long rightCost = dominantA(k, a, mid + 1, right);
    //if (k.size() == 131072 && right - left <= 1)
      //  cout << "left : " << left << " Right : " << right << " mid : " << mid << '\n';

    return dp[depth][left] = min(leftCost + help(mid + 1, right, k, cnt, depth + 1), rightCost + help(left, mid, k, cnt, depth + 1));
}
int main() {
    //std::ios_base::sync_with_stdio(false);
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        string s;
        cin >> s;
        long cnt[n + 1][26];
        for (auto & i : dp) {
            for (int j = 0; j <= n; j++)
                i[j] = -1;
        }

        cout << help(0, n - 1,  s, cnt, 0) << '\n';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <map>
#include <queue>
#include <cmath>
using std::vector;
using std::cin;
using std::cout;

using namespace std;

int dominantA (string k, char a, int left, int right) {

    int score = 0;
    for (int i = left; i <= right; i++) {
        score += (26 - abs(a - k[i]));
    }
    return score;
}

int dp [18][131075];

int help (int left, int right, string k, int cnt[][26], int depth) {

    int a = 'a' + depth;
    if (a > 'z' || depth > 17 || left > right || left < 0 || right >= k.size())
        return (int)10e8;

    if (left == right) {
        if (k[left] == a)
            return 0;
        else
            return 1;
    }

    if (dp[depth][left] != -1)
        return dp[depth][left];

    int mid = ((right - left) / 2) + left;
    int leftCost = mid - left + 1 - (cnt[mid + 1][a - 'a'] - cnt[left][a - 'a']);
    int rightCost = right - mid - (cnt[right + 1][a - 'a'] - cnt[mid + 1][a - 'a']);

    return dp[depth][left] = min(leftCost + help(mid + 1, right, k, cnt, depth + 1), rightCost + help(left, mid, k, cnt, depth + 1));
}
int main() {
    std::ios_base::sync_with_stdio(false);
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        string s;
        cin >> s;

        int cnt[n + 1][26];
        for (int i = 0; i < 19; i++) for (int j = 0; j <= n; j++) dp[i][j] = -1;
        for (int i = 0; i < 26; i++) cnt[0][i] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j];
            cnt[i][s[i - 1] - 'a']++;
        }
        cout << help(0, n - 1,  s, cnt, 0) << '\n';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <map>
#include <queue>
#include <cmath>
using std::vector;
using std::cin;
using std::cout;

using namespace std;

int dominantA (string k, char a, int left, int right) {

    int score = 0;
    for (int i = left; i <= right; i++) {
        if (k[i] != a)
            score++;
    }
    return score;
}

long help (long left, long right, string k, char a) {

    if (a > 'z' || a < 'a' || left > right || left < 0 || right >= k.size())
        return (int)10e8;

    if (left == right) {
        if (k[left] == a)
            return 0;
        else
            return 1;
    }
    long mid = (left + right) / 2;
    long leftCost = dominantA(k, a, left, mid);
    long rightCost = dominantA(k, a, mid + 1, right);

    return min(leftCost + help(mid + 1, right, k, (char)(a + 1)), rightCost + help(left, mid, k, (char)(a + 1)));
}
int main() {
    //std::ios_base::sync_with_stdio(false);
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        string s;
        cin >> s;
        cout << help(0, n - 1,  s,  0) << '\n';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <map>
#include <queue>
#include <cmath>
using std::vector;
using std::cin;
using std::cout;

using namespace std;

int dominantA (string k, int a, int left, int right) {

    int score = 0;
    for (int i = left; i <= right; i++) {
        if (k[i] != (char)a)
            score++;
    }
    return score;
}

long help (long left, long right, string k, long depth) {

    int a = 'a' + depth;
    if (a > 'z' || depth > 18 || left > right || left < 0 || right >= k.size())
        return (int)10e8;

    if (left == right) {
        if (k[left] == a)
            return 0;
        else
            return 1;
    }
    long mid = (left + right) / 2;
    long leftCost = dominantA(k, a, left, mid);
    long rightCost = dominantA(k, a, mid + 1, right);

    return min(leftCost + help(mid + 1, right, k, depth + 1), rightCost + help(left, mid, k, depth + 1));
}
int main() {
    //std::ios_base::sync_with_stdio(false);
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        string s;
        cin >> s;
        cout << help(0, n - 1,  s,  0) << '\n';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <map>
#include <queue>
#include <cmath>
using std::vector;
using std::cin;
using std::cout;

using namespace std;

int dominantA (string k, char a, int left, int right) {

    int score = 0;
    for (int i = left; i <= right; i++) {
        score += (26 - abs(a - k[i]));
    }
    return score;
}

int dp [20][131075];

int help (int left, int right, string k, int cnt[][26], int depth) {

    int a = 'a' + depth;
    if (a > 'z' || depth > 18 || left > right || left < 0 || right >= k.size())
        return (int)10e8;

    if (left == right) {
        if (k[left] == a)
            return 0;
        else
            return 1;
    }
    if (right < left)
        return (int)10e8;

    if (dp[depth][left] != -1)
        return dp[depth][left];

    int mid = ((long)left + right + 1) / 2;
    mid--;
    int leftCost = mid - left + 1 - (cnt[mid + 1][a - 'a'] - cnt[left][a - 'a']);
    int rightCost = right - mid - (cnt[right + 1][a - 'a'] - cnt[mid + 1][a - 'a']);
    if (k.size() == 131072)
        cout << "left : " << left << " Right : " << right << " mid : " << mid << '\n';

    return dp[depth][left] = min(leftCost + help(mid + 1, right, k, cnt, depth + 1), rightCost + help(left, mid, k, cnt, depth + 1));
}
int main() {
    std::ios_base::sync_with_stdio(false);
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        string s;
        cin >> s;

        int cnt[n + 1][26];
        for (auto & i : dp) for (int j = 0; j <= n; j++) i[j] = -1;
        for (int i = 0; i < 26; i++) cnt[0][i] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j];
            cnt[i][s[i - 1] - 'a']++;
        }
        cout << help(0, n - 1,  s, cnt, 0) << '\n';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <map>
#include <queue>
#include <cmath>
using std::vector;
using std::cin;
using std::cout;

using namespace std;

int dominantA (const string& k, char a, int left, int right) {

    int score = 0;
    for (int i = left; i <= right; i++) {
        if (k[i] != a)
            score++;
    }
    return score;
}

long help (long left, long right, const string& k, char a) {

    if (left == right) {
        return (k[left] != a ? 1 : 0);
    }
    long mid = (left + right) / 2;
    long leftCost = dominantA(k, a, left, mid);
    long rightCost = dominantA(k, a, mid + 1, right);

    return min(leftCost + help(mid + 1, right, k, (char)(a + 1)), rightCost + help(left, mid, k, (char)(a + 1)));
}
int main() {
    //std::ios_base::sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        string s;
        cin >> s;
        cout << help(0, n - 1,  s,  'a') << '\n';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <map>
#include <queue>
#include <cmath>
using std::vector;
using std::cin;
using std::cout;

using namespace std;

int dominantA (string k, char a, int left, int right) {

    int score = 0;
    for (int i = left; i <= right; i++) {
        score += (26 - abs(a - k[i]));
    }
    return score;
}

long dp [20][131075];

long help (long left, long right, string k, long cnt[][26], long depth) {

    int a = 'a' + depth;
    if (a > 'z' || depth > 18 || left > right || left < 0 || right >= k.size())
        return (int)10e8;

    if (left == right) {
        if (k[left] == a)
            return 0;
        else
            return 1;
    }
    long mid = ((long)left + right + 1) / 2;
    mid--;
    long leftCost = mid - left + 1 - (cnt[mid + 1][a - 'a'] - cnt[left][a - 'a']);
    long rightCost = right - mid - (cnt[right + 1][a - 'a'] - cnt[mid + 1][a - 'a']);
    //if (k.size() == 131072 && right - left <= 1)
      //  cout << "left : " << left << " Right : " << right << " mid : " << mid << '\n';

    return dp[depth][left] = min(leftCost + help(mid + 1, right, k, cnt, depth + 1), rightCost + help(left, mid, k, cnt, depth + 1));
}
int main() {
    //std::ios_base::sync_with_stdio(false);
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        string s;
        cin >> s;

        long cnt[n + 1][26];
        for (auto & i : dp) for (int j = 0; j <= n; j++) i[j] = -1;
        for (int i = 0; i < 26; i++) cnt[0][i] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j];
            cnt[i][s[i - 1] - 'a']++;
        }
        cout << help(0, n - 1,  s, cnt, 0) << '\n';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <map>
#include <queue>
#include <cmath>
using std::vector;
using std::cin;
using std::cout;

using namespace std;

int dominantA (string k, char a, int left, int right) {

    int score = 0;
    for (int i = left; i <= right; i++) {
        score += (26 - abs(a - k[i]));
    }
    return score;
}

int dp [20][131075];

int help (int left, int right, string k, int cnt[][26], int depth) {

    int a = 'a' + depth;
    if (a > 'z' || depth > 18 || left > right || left < 0 || right >= k.size())
        return (int)10e8;

    if (left == right) {
        if (k[left] == a)
            return 0;
        else
            return 1;
    }
    if (right < left)
        return (int)10e8;

    if (dp[depth][left] != -1)
        return dp[depth][left];

    int mid = ((long)left + right + 1) / 2;
    mid--;
    int leftCost = mid - left + 1 - (cnt[mid + 1][a - 'a'] - cnt[left][a - 'a']);
    int rightCost = right - mid - (cnt[right + 1][a - 'a'] - cnt[mid + 1][a - 'a']);
    if (k.size() == 131072 && right - left <= 1)
        cout << "left : " << left << " Right : " << right << " mid : " << mid << '\n';

    return dp[depth][left] = min(leftCost + help(mid + 1, right, k, cnt, depth + 1), rightCost + help(left, mid, k, cnt, depth + 1));
}
int main() {
    std::ios_base::sync_with_stdio(false);
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        string s;
        cin >> s;

        int cnt[n + 1][26];
        for (auto & i : dp) for (int j = 0; j <= n; j++) i[j] = -1;
        for (int i = 0; i < 26; i++) cnt[0][i] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j];
            cnt[i][s[i - 1] - 'a']++;
        }
        cout << help(0, n - 1,  s, cnt, 0) << '\n';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <map>
#include <queue>
#include <cmath>
using std::vector;
using std::cin;
using std::cout;

using namespace std;

int dominantA (string k, char a, int left, int right) {

    int score = 0;
    for (int i = left; i <= right; i++) {
        score += (26 - abs(a - k[i]));
    }
    return score;
}

int dp [20][131075];

int help (int left, int right, string k, int cnt[][26], int depth) {

    int a = 'a' + depth;
    if (a > 'z' || depth > 18 || left > right || left < 0 || right >= k.size())
        return (int)10e8;

    if (left == right) {
        if (k[left] == a)
            return 0;
        else
            return 1;
    }
    if (right < left)
        return (int)10e8;

    if (dp[depth][left] != -1)
        return dp[depth][left];

    int mid = ((long)left + right + 1) / 2;
    mid--;
    int leftCost = mid - left + 1 - (cnt[mid + 1][a - 'a'] - cnt[left][a - 'a']);
    int rightCost = right - mid - (cnt[right + 1][a - 'a'] - cnt[mid + 1][a - 'a']);

    return dp[depth][left] = min(leftCost + help(mid + 1, right, k, cnt, depth + 1), rightCost + help(left, mid, k, cnt, depth + 1));
}
int main() {
    std::ios_base::sync_with_stdio(false);
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        string s;
        cin >> s;

        int cnt[n + 1][26];
        for (auto & i : dp) for (int j = 0; j <= n; j++) i[j] = -1;
        for (int i = 0; i < 26; i++) cnt[0][i] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j];
            cnt[i][s[i - 1] - 'a']++;
        }
        cout << help(0, n - 1,  s, cnt, 0) << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0)
#define F first
#define S second
//#define endl '\n'

using namespace std;

const int maxx = 200000;

int len;
string s;
map<int , int> pre[maxx];

int solve(int l,int r,int z) {
    if (l > r)return 0;
    if (l == r)return s[l] - 'a' != z;
    int ret;
    int mid = (l + r) >> 1;
    ret = solve(l , mid , z + 1) + (mid - l + 1) - (pre[z][r] - pre[z][mid]);
    ret = min(ret , solve(mid + 1 , r , z + 1) + (mid - l + 1) - (pre[z][mid] - pre[z][l - 1]));
    return ret; //cout<<ret<<endl;
}

int main() {
    FAST_IO;
    int t;
    cin>>t;
    while (t--) {
        cin>>len;
        s = "_";
        for (int i = 1;i<=len;i++)s += 'a';
        for (int i = 1;i<=len;i++) {
            for (char a = 'a';a <= 'z';a++) pre[a - 'a'][i] = pre[a - 'a'][i - 1];
            pre[s[i] - 'a'][i]++;
        }
        if (len == 1) {
            cout<<(s[1] != 'a')<<endl;
            continue;
        }
        int ret;
        ret = solve(1 , len / 2 , 1) + len / 2 - (pre[0][len] - pre[0][len / 2]);
        ret = min(ret , solve(len / 2 + 1 , len , 1) + len / 2 - pre[0][len / 2]);
        cout<<ret<<endl;
    }
}


#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0)
#define F first
#define S second
#define endl '\n'

using namespace std;

const int maxx = 200000;

int len;
string s;
int pre[26][maxx];

int solve(int l,int r,int z) {
    if (l > r)return 0;
    if (l == r)return s[l] - 'a' != z;
    int ret;
    int mid = (l + r) >> 1;
    ret = solve(l , mid , z + 1) + (mid - l + 1) - (pre[z][r] - pre[z][mid]);
    ret = min(ret , solve(mid + 1 , r , z + 1) + (mid - l + 1) - (pre[z][mid] - pre[z][l - 1]));
    return ret; //cout<<ret<<endl;
}

int main() {
    FAST_IO;
    int t;
    cin>>t;
    while (t--) {
        cin>>len>>s;
        s = '_' + s;
        for (int i = 1;i<=len;i++) {
            for (char a = 'a';a <= 'z';a++) pre[a - 'a'][i] = pre[a - 'a'][i - 1];
            pre[s[i] - 'a'][i]++;
        }
        if (len == 1) {
            cout<<(s[1] != 'a')<<endl;
            continue;
        }
        int ret;
        ret = solve(1 , len / 2 , 1) + len / 2 - (pre[0][len] - pre[0][len / 2]);
        ret = min(ret , solve(len / 2 + 1 , len , 1) + len / 2 - pre[0][len / 2]);
        cout<<ret<<endl;
    }
}


#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0)
#define F first
#define S second
#define endl '\n'

using namespace std;

const int maxx = 200000;

int len;
string s;
map<char , int>pre[maxx];

int solve(int l,int r,char z) {
    if (l > r)return 0;
    if (l == r)return s[l] != z;
    int ret;
    int mid = (l + r) >> 1;
    ret = solve(l , mid , z + 1) + (mid - l + 1) - (pre[z][r] - pre[z][mid]);
    ret = min(ret , solve(mid + 1 , r , z + 1) + (mid - l + 1) - (pre[z][mid] - pre[z][l - 1]));
    return ret; //cout<<ret<<endl;
}

int main() {
    FAST_IO;
    int t;
    cin>>t;
    while (t--) {
        cin>>len>>s;
        s = '-' + s;
        for (int i = 1;i<=len;i++) {
            for (char a = 'a';a <= 'z';a++) pre[a][i] = pre[a][i - 1];
            pre[s[i]][i]++;
        }
        if (len == 1) {
            cout<<(s[1] != 'a')<<endl;
            continue;
        }
        int ret;
        ret = solve(1 , len / 2 , 'b') + len / 2 - (pre['a'][len] - pre['a'][len / 2 - 1]);
        ret = min(ret , solve(len / 2 + 1 , len , 'b') + len / 2 - pre['a'][len / 2]);
        cout<<ret<<endl;
    }
}


#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0)
#define F first
#define S second
//#define endl '\n'

using namespace std;

const int maxx = 200000;

int len;
string s;
map<int , int> pre[maxx];

int solve(int l,int r,int z) {
    if (l > r)return 0;
    if (l == r)return s[l] - 'a' != z;
    int ret;
    int mid = (l + r) >> 1;
    ret = solve(l , mid , z + 1) + (mid - l + 1) - (pre[z][r] - pre[z][mid]);
    ret = min(ret , solve(mid + 1 , r , z + 1) + (mid - l + 1) - (pre[z][mid] - pre[z][l - 1]));
    return ret; //cout<<ret<<endl;
}

int main() {
    FAST_IO;
    int t;
    cin>>t;
    while (t--) {
        cin>>len>>s;
        //s = "_";
        //for (int i = 1;i<=len;i++)s += 'a';
        s = '-' + s;
        for (int i = 1;i<=len;i++) {
            for (char a = 'a';a <= 'z';a++) pre[a - 'a'][i] = pre[a - 'a'][i - 1];
            pre[s[i] - 'a'][i]++;
        }
        if (len == 1) {
            cout<<(s[1] != 'a')<<endl;
            continue;
        }
        int ret;
        ret = solve(1 , len / 2 , 1) + len / 2 - (pre[0][len] - pre[0][len / 2]);
        ret = min(ret , solve(len / 2 + 1 , len , 1) + len / 2 - pre[0][len / 2]);
        cout<<ret<<endl;
    }
}


#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0)
#define F first
#define S second
#define endl '\n'

using namespace std;

const int maxx = 200000;

int len;
map<char,int>pre[maxx];
string s;

int solve(int l,int r,char z) {
    if (l == r) {
        return (s[l] != z);
    }
    int mid = (l + r) >> 1;
    int ret = solve(mid + 1 , r , z + 1) + (mid - l + 1) - pre[z][mid] + pre[z][l - 1];
    ret = min(ret , solve(l , mid , z + 1) + (mid - l + 1) - pre[z][r] + pre[z][mid]);
    return ret;
}

int main() {
    FAST_IO;
    int t;
    cin>>t;
    while (t--) {
        cin>>len>>s;
        for (int i = 0;i<len;i++) {
            for (char j = 'a';j<='z';j++) {
                if (i == 0)pre[j][i] = 0;
                else pre[j][i] = pre[j][i - 1];
            }
            pre[s[i]][i]++;
        }
        if (len == 1) {
            cout<<(s[0] != 'a')<<endl;
            continue;
        }
        int ret = solve(0 , len / 2 - 1 , 'b') + len / 2- pre['a'][len - 1] + pre['a'][len / 2 - 1];
        ret = min(ret , solve(len / 2 , len - 1 , 'b') + len / 2  - pre['a'][len / 2 - 1]);
        cout<<ret<<endl;
    }
}


#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0)
#define F first
#define S second
//#define endl '\n'

using namespace std;

const int maxx = 200000;

int len;
string s;
map<char , int> pre[maxx];

int solve(int l,int r,int z) {
    if (l > r)return 0;
    if (l == r)return s[l] - 'a' != z;
    int ret;
    int mid = (l + r) >> 1;
    ret = solve(l , mid , z + 1) + (mid - l + 1) - (pre[z][r] - pre[z][mid]);
    ret = min(ret , solve(mid + 1 , r , z + 1) + (mid - l + 1) - (pre[z][mid] - pre[z][l - 1]));
    return ret; //cout<<ret<<endl;
}

int main() {
    FAST_IO;
    int t;
    cin>>t;
    while (t--) {
        cin>>len>>s;
        //s = "_";
        //for (int i = 1;i<=len;i++)s += 'a';
        s = '-' + s;
        for (int i = 1;i<=len;i++) {
            for (char a = 'a';a <= 'z';a++) pre[a - 'a'][i] = pre[a - 'a'][i - 1];
            pre[s[i] - 'a'][i]++;
        }
        if (len == 1) {
            cout<<(s[1] != 'a')<<endl;
            continue;
        }
        int ret;
        ret = solve(1 , len / 2 , 1) + len / 2 - (pre[0][len] - pre[0][len / 2]);
        ret = min(ret , solve(len / 2 + 1 , len , 1) + len / 2 - pre[0][len / 2]);
        cout<<ret<<endl;
    }
}


#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0)
#define F first
#define S second
#define endl '\n'

using namespace std;

const int maxx = 200000;

int len;
string s;
map<char , int>pre[maxx];

int solve(int l,int r,char z) {
    if (l > r)return 0;
    if (l == r)return s[l] != z;
    int ret;
    int mid = (l + r) >> 1;
    ret = solve(l , mid , z + 1) + (mid - l + 1) - (pre[z][r] - pre[z][mid]);
    ret = min(ret , solve(mid + 1 , r , z + 1) + (mid - l + 1) - (pre[z][mid] - pre[z][l - 1]));
    return ret; //cout<<ret<<endl;
}

int main() {
    FAST_IO;
    int t;
    cin>>t;
    while (t--) {
        cin>>len>>s;
        s = '-' + s;
        for (int i = 1;i<=len;i++) {
            for (char a = 'a';a <= 'z';a++) pre[a][i] = pre[a][i - 1];
            pre[s[i]][i]++;
        }
        if (len == 1) {
            cout<<(s[1] != 'a')<<endl;
            continue;
        }
        int ret;
        ret = solve(1 , len / 2 , 'b') + len / 2 - (pre['a'][len] - pre['a'][len / 2]);
        ret = min(ret , solve(len / 2 + 1 , len , 'b') + len / 2 - pre['a'][len / 2]);
        cout<<ret<<endl;
    }
}


#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0)
#define F first
#define S second
#define endl '\n'

using namespace std;

int lg2(int x) {
    int ret = 0;
    while (x > 1) {
        ret++;
        x /= 2;
    }
    return ret;
}

int pre[26][200001];

int main() {
    FAST_IO;
    int t;
    cin>>t;
    while (t--) {
        int n; string s;
        cin>>n>>s;
        s = '-' + s;
        for (int i = 1;i<=n;i++) {
            for (int j = 0;j<26;j++)pre[j][i] = pre[j][i - 1];
            pre[s[i] - 'a'][i]++;
        }
        int lg = lg2(n) + 1;
        int dp[lg][n];
        memset(dp , 0 , sizeof(dp));
        for (int i = 0;i<lg;i++) {
            char a = 'a' + lg - i - 1;
            for (int j = 1;j<=n;j += (1 << i)) {
                if (i == 0)dp[i][j] = s[j] != a;
                else {
                    int add = (1 << (i - 1)) - (pre[a - 'a'][j + (1 << i) - 1] - pre[a - 'a'][j + (1 << (i - 1)) - 1]);
                    dp[i][j] = dp[i - 1][j] + add;
                    add = (1 << (i - 1)) - (pre[a - 'a'][j + (1 << (i - 1)) - 1] - pre[a - 'a'][j - 1]);
                    dp[i][j] = min(dp[i][j] , dp[i - 1][j + (1 << (i - 1))] + add);
                }
                //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
            }
        }
        cout<<dp[lg - 1][1]<<endl;/**/
    }
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

const int N = 131079;
int pre[26][N+4];
ll n,k;
string s;
int ppp[20];

ll go(ll l,ll p,int ch){
    if(ch>25)re INT_MAX;
    if(p==0){
        if(char(ch+'a')==s[l])re 0;
        else re 1;
    }

    ll fin = INT_MAX;

    ll end = l+ppp[p]-1; ll mid = l+ppp[p-1];
    ll ans1 = go(mid,p-1,ch+1);
    if(ans1!=INT_MAX)ans1 += ppp[p-1] - ( pre[ch][mid-1]-pre[ch][l-1] );

    ll ans2 = go(l,p-1,ch+1);
    if(ans2!=INT_MAX)ans2 +=  ppp[p-1] - ( pre[ch][end]-pre[ch][mid-1] );

    if(ans1!=INT_MAX) fin = min(fin,ans1);
    if(ans2!=INT_MAX) fin = min(fin,ans2);
    re fin;

}
void formpre(){
    for(int c=0;c<26;c++){
        fo(i,1,n){
            if(s[i]==char('a'+c))pre[c][i]++;
            pre[c][i] += pre[c][i-1];
        }
    }
}

void solve()
{
    mem(pre,0);
    // mem(cache,-1);
    rd(n);
    rd(s);
    s = "#" + s;
    formpre();
    ll temp = n;
    k = 0;
    while(temp!=1){
        k++;temp/=2;
    }

    ll ans = go(1,k,0);
    pp(ans);

}

void prep(){
	fo(i,0,19)ppp[i]=p2(i);
}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

const int N = 131079;
int pre[26][N+4];
ll n,k;
string s;

ll go(ll l,ll p,int ch){
    if(ch>25)re INT_MAX;
    if(p==0){
        if(char(ch+'a')==s[l])re 0;
        else re 1;
    }

    ll fin = INT_MAX;

    ll end = l+p2(p)-1; ll mid = l+p2(p-1);
    ll ans1 = go(mid,p-1,ch+1);
    if(ans1!=INT_MAX)ans1 += p2(p-1) - ( pre[ch][mid-1]-pre[ch][l-1] );

    ll ans2 = go(l,p-1,ch+1);
    if(ans2!=INT_MAX)ans2 +=  p2(p-1) - ( pre[ch][end]-pre[ch][mid-1] );

    if(ans1!=INT_MAX) fin = min(fin,ans1);
    if(ans2!=INT_MAX) fin = min(fin,ans2);
    re fin;

}
void formpre(){
    for(int c=0;c<26;c++){
        fo(i,1,n){
            if(s[i]==char('a'+c))pre[c][i]++;
            pre[c][i] += pre[c][i-1];
        }
    }
}

void solve()
{
    mem(pre,0);
    // mem(cache,-1);
    rd(n);
    rd(s);
    s = "#" + s;
    formpre();
    ll temp = n;
    k = 0;
    while(temp!=1){
        k++;temp/=2;
    }

    ll ans = go(1,k,0);
    pp(ans);

}

void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

const int N = 131079;
int pre[26][N+4];
int n,k;
string s;
int cache[131079][20];
int ppp[20];
int go(int l,int p){
    int ch = k - p;
    if(ch>25)re INT_MAX;

    int &fin = cache[l][p];
    if(fin!=-1)re fin;
    fin = INT_MAX;

    if(p==0){
        if(char(ch+'a')==s[l])re 0;
        else re 1;
    }

    int end = l+p2(p)-1; int mid = l+ppp[p-1];
    int ans1 = go(mid,p-1);
    if(ans1!=INT_MAX)ans1 += ppp[p-1] - ( pre[ch][mid-1]-pre[ch][l-1] );

    int ans2 = go(l,p-1);
    if(ans2!=INT_MAX)ans2 +=  ppp[p-1] - ( pre[ch][end]-pre[ch][mid-1] );

    if(ans1!=INT_MAX) fin = min(fin,ans1);
    if(ans2!=INT_MAX) fin = min(fin,ans2);
    cache[l][p] = fin;
    re fin;

}
void formpre(){
    for(int c=0;c<26;c++){
        fo(i,1,n){
            if(s[i]==char('a'+c))pre[c][i]++;
            pre[c][i] += pre[c][i-1];
        }
    }
}

void solve()
{
    fo(i,0,n){
        fo(c,0,25)pre[c][i] = 0;
    }
    // mem(cache,-1);
    rd(n);
    rd(s);
    s = "#" + s;
    formpre();
    int temp = n;
    k = 0;
    while(temp!=1){
        k++;temp/=2;
    }
    fo(i,0,n){
            fo(k,0,19)cache[i][k]=-1;
    }
    int ans = go(1,k);
    pp(ans);

}

void prep(){
    fo(i,0,19)ppp[i] = p2(i);
}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

const int N = 131079;
int pre[26][N+4];
ll n,k;
string s;
int ppp[20];

ll go(ll l,ll p,int ch){
    if(p==0){
        re char(ch+'a')!=s[l];
    }

    ll end = l+ppp[p]-1; ll mid = l+ppp[p-1];
    ll ans1 = go(mid,p-1,ch+1) + ppp[p-1] - ( pre[ch][mid-1]-pre[ch][l-1] );
    ll ans2 = go(l,p-1,ch+1) + ppp[p-1] - ( pre[ch][end]-pre[ch][mid-1] );
    re min(ans1,ans2);

}
void formpre(){
    for(int c=0;c<26;c++){
        fo(i,1,n){
            if(s[i]==char('a'+c))pre[c][i]++;
            pre[c][i] += pre[c][i-1];
        }
    }
}

void solve()
{
    // mem(pre,0);
    // mem(cache,-1);
	for(int c=0;c<26;c++){
        fo(i,0,n){
            pre[c][i]=0;
        }
    }
    rd(n);
    rd(s);
    s = "#" + s;
    formpre();
    ll temp = n;
    k = 0;
    while(temp!=1){
        k++;temp/=2;
    }

    ll ans = go(1,k,0);
    pp(ans);

}

void prep(){
	fo(i,0,19)ppp[i]=p2(i);
}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

const int N = 131079;
int pre[26][N+4];
int n,k;
string s;
int cache[131079][18];

int go(int l,int p){
    int ch = k - p;
    if(ch>25)re INT_MAX;
    if(p==0){
        if(char(ch+'a')==s[l])re 0;
        else re 1;
    }

    int &fin = cache[l][p];
    if(fin!=-1)re fin;
    fin = INT_MAX;

    int end = l+p2(p)-1; int mid = l+p2(p-1);
    int ans1 = go(mid,p-1);
    if(ans1!=INT_MAX)ans1 += p2(p-1) - ( pre[ch][mid-1]-pre[ch][l-1] );

    int ans2 = go(l,p-1);
    if(ans2!=INT_MAX)ans2 +=  p2(p-1) - ( pre[ch][end]-pre[ch][mid-1] );

    if(ans1!=INT_MAX) fin = min(fin,ans1);
    if(ans2!=INT_MAX) fin = min(fin,ans2);
    re fin;

}
void formpre(){
    for(int c=0;c<26;c++){
        fo(i,1,n){
            if(s[i]==char('a'+c))pre[c][i]++;
            pre[c][i] += pre[c][i-1];
        }
    }
}

void solve()
{
    mem(pre,0);
    // mem(cache,-1);
    rd(n);
    rd(s);
    s = "#" + s;
    formpre();
    int temp = n;
    k = 0;
    while(temp!=1){
        k++;temp/=2;
    }
    fo(i,0,n){
        fo(j,0,19){
            fo(k,0,25)cache[i][j]=-1;
        }
    }
    int ans = go(1,k);
    pp(ans);

}

void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

const int N = 131079;
int pre[26][N+4];
ll n,k;
string s;
ll cache[131079][20][26];

ll go(ll l,ll p,int ch){
    if(ch>25)re INT_MAX;
    if(p==0){
        if(char(ch+'a')==s[l])re 0;
        else re 1;
    }

    ll fin = cache[l][p][ch];
    if(fin!=-1)re fin;
    fin = INT_MAX;

    ll end = l+p2(p)-1; ll mid = l+p2(p-1);
    ll ans1 = go(mid,p-1,ch+1);
    if(ans1!=INT_MAX)ans1 += p2(p-1) - ( pre[ch][mid-1]-pre[ch][l-1] );

    ll ans2 = go(l,p-1,ch+1);
    if(ans2!=INT_MAX)ans2 +=  p2(p-1) - ( pre[ch][end]-pre[ch][mid-1] );

    if(ans1!=INT_MAX) fin = min(fin,ans1);
    if(ans2!=INT_MAX) fin = min(fin,ans2);
    re fin;

}
void formpre(){
    for(int c=0;c<26;c++){
        fo(i,1,n){
            if(s[i]==char('a'+c))pre[c][i]++;
            pre[c][i] += pre[c][i-1];
        }
    }
}

void solve()
{
    mem(pre,0);
    // mem(cache,-1);
    rd(n);
    rd(s);
    s = "#" + s;
    formpre();
    ll temp = n;
    k = 0;
    while(temp!=1){
        k++;temp/=2;
    }
    fo(i,0,n){
        fo(j,0,19){
            fo(k,0,25)cache[i][j][k]=-1;
        }
    }
    ll ans = go(1,k,0);
    pp(ans);

}

void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

const int N = 131079;
int pre[26][N+4];
ll n,k;
string s;
int cache[131079][20][26];

ll go(ll l,ll p,int ch){
    if(ch>25)re INT_MAX;
    if(p==0){
        if(char(ch+'a')==s[l])re 0;
        else re 1;
    }

    ll fin = cache[l][p][ch];
    if(fin!=-1)re fin;
    fin = INT_MAX;

    ll end = l+p2(p)-1; ll mid = l+p2(p-1);
    ll ans1 = go(mid,p-1,ch+1);
    if(ans1!=INT_MAX)ans1 += p2(p-1) - ( pre[ch][mid-1]-pre[ch][l-1] );

    ll ans2 = go(l,p-1,ch+1);
    if(ans2!=INT_MAX)ans2 +=  p2(p-1) - ( pre[ch][end]-pre[ch][mid-1] );

    if(ans1!=INT_MAX) fin = min(fin,ans1);
    if(ans2!=INT_MAX) fin = min(fin,ans2);
    re fin;

}
void formpre(){
    for(int c=0;c<26;c++){
        fo(i,1,n){
            if(s[i]==char('a'+c))pre[c][i]++;
            pre[c][i] += pre[c][i-1];
        }
    }
}

void solve()
{
    mem(pre,0);
    // mem(cache,-1);
    rd(n);
    rd(s);
    s = "#" + s;
    formpre();
    ll temp = n;
    k = 0;
    while(temp!=1){
        k++;temp/=2;
    }
    fo(i,0,n){
        fo(j,0,19){
            fo(k,0,25)cache[i][j][k]=-1;
        }
    }
    ll ans = go(1,k,0);
    pp(ans);

}

void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

const int N = 131079;
int pre[26][N+4];
int n,k;
string s;
int cache[131079][20];
int ppp[20];
int go(int l,int p){
    int ch = k - p;
    if(ch>25)re INT_MAX;

    int &fin = cache[l][p];
    if(fin!=-1)re fin;
    fin = INT_MAX;

    if(p==0){
        if(char(ch+'a')==s[l])re 0;
        else re 1;
    }

    int end = l+p2(p)-1; int mid = l+ppp[p-1];
    int ans1 = go(mid,p-1);
    if(ans1!=INT_MAX)ans1 += ppp[p-1] - ( pre[ch][mid-1]-pre[ch][l-1] );

    int ans2 = go(l,p-1);
    if(ans2!=INT_MAX)ans2 +=  ppp[p-1] - ( pre[ch][end]-pre[ch][mid-1] );

    if(ans1!=INT_MAX) fin = min(fin,ans1);
    if(ans2!=INT_MAX) fin = min(fin,ans2);
    cache[l][p] = fin;
    re fin;

}
void formpre(){
    for(int c=0;c<26;c++){
        fo(i,1,n){
            if(s[i]==char('a'+c))pre[c][i]++;
            pre[c][i] += pre[c][i-1];
        }
    }
}

void solve()
{
    mem(pre,0);
    // mem(cache,-1);
    rd(n);
    rd(s);
    s = "#" + s;
    formpre();
    int temp = n;
    k = 0;
    while(temp!=1){
        k++;temp/=2;
    }
    fo(i,0,n){
            fo(k,0,19)cache[i][k]=-1;
    }
    int ans = go(1,k);
    pp(ans);

}

void prep(){
    fo(i,0,19)ppp[i] = p2(i);
}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

struct pair_hash {
    template <class T1, class T2, class T3>
    std::size_t operator () (const std::tuple<T1,T2,T3> &p) const {
        auto h1 = std::hash<T1>{}(get<0>(p));
        auto h2 = std::hash<T2>{}(get<1>(p));
        auto h3 = std::hash<T2>{}(get<2>(p));

        // Mainly for demonstration purposes, i.e. works but is overly simple
        // In the real world, use sth. like boost.hash_combine
        return h1 ^ h2 ^ h3;
    }
};

const int N = 131072;
int pre[26][N+4];
ll n,k;
string s;
unordered_map<tuple<int,int,int> ,int, pair_hash>mp;

// int cache[131073][18][26];

ll go(ll l,ll p,int ch){
    if(ch>25)re INT_MAX;
    if(p==0){
        if(char(ch+'a')==s[l])re 0;
        else re 1;
    }

    tuple<int,int,int> t = make_tuple(l,p,ch);
    if(mp.find(t)!=mp.end())return mp[t];

    // int &fin = cache[l][p][ch];
    // if(fin!=-1)re fin;
    int fin = INT_MAX;

    int end = l+p2(p)-1; int mid = l+p2(p-1);
    int ans1 = go(mid,p-1,ch+1);
    if(ans1!=INT_MAX)ans1 += p2(p-1) - ( pre[ch][mid-1]-pre[ch][l-1] );

    int ans2 = go(l,p-1,ch+1);
    if(ans2!=INT_MAX)ans2 +=  p2(p-1) - ( pre[ch][end]-pre[ch][mid-1] );

    if(ans1!=INT_MAX) fin = min(fin,ans1);
    if(ans2!=INT_MAX) fin = min(fin,ans2);
    mp[t] = fin;
    re fin;

}
void formpre(){
    for(int c=0;c<26;c++){
        fo(i,1,n){
            if(s[i]==char('a'+c))pre[c][i]++;
            pre[c][i] += pre[c][i-1];
        }
    }
}

void solve()
{
    mem(pre,0);
    mp.clear();
    // mem(cache,-1);
    rd(n);
    rd(s);
    s = "#" + s;
    formpre();
    ll temp = n;
    k = 0;
    while(temp!=1){
        k++;temp/=2;
    }
    // fo(i,0,n){
    //     fo(j,0,19){
    //         fo(k,0,25)cache[i][j][k]=-1;
    //     }
    // }
    ll ans = go(1,k,0);
    pp(ans);

}

void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

const int N = 131072;
int pre[26][N+4];
ll n,k;
string s;
map<tuple<int,int,int> ,int>mp;

// int cache[131073][18][26];

ll go(ll l,ll p,int ch){
    if(ch>25)re INT_MAX;
    if(p==0){
        if(char(ch+'a')==s[l])re 0;
        else re 1;
    }

    tuple<int,int,int> t = make_tuple(l,p,ch);
    if(mp.find(t)!=mp.end())return mp[t];

    // int &fin = cache[l][p][ch];
    // if(fin!=-1)re fin;
    int fin = INT_MAX;

    int end = l+p2(p)-1; int mid = l+p2(p-1);
    int ans1 = go(mid,p-1,ch+1);
    if(ans1!=INT_MAX)ans1 += p2(p-1) - ( pre[ch][mid-1]-pre[ch][l-1] );

    int ans2 = go(l,p-1,ch+1);
    if(ans2!=INT_MAX)ans2 +=  p2(p-1) - ( pre[ch][end]-pre[ch][mid-1] );

    if(ans1!=INT_MAX) fin = min(fin,ans1);
    if(ans2!=INT_MAX) fin = min(fin,ans2);
    mp[t] = fin;
    re fin;

}
void formpre(){
    for(int c=0;c<26;c++){
        fo(i,1,n){
            if(s[i]==char('a'+c))pre[c][i]++;
            pre[c][i] += pre[c][i-1];
        }
    }
}

void solve()
{
    mem(pre,0);
    mp.clear();
    // mem(cache,-1);
    rd(n);
    rd(s);
    s = "#" + s;
    formpre();
    ll temp = n;
    k = 0;
    while(temp!=1){
        k++;temp/=2;
    }
    // fo(i,0,n){
    //     fo(j,0,19){
    //         fo(k,0,25)cache[i][j][k]=-1;
    //     }
    // }
    ll ans = go(1,k,0);
    pp(ans);

}

void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    cin >> t;
    while(t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

ll getCost(string input,ll s,ll e,char ch){
    ll cost = 0;
    for(ll i=s;i<=e;i++){
        if(input[i]!=ch)cost++ ;
    }

    return cost;
}

ll solve(string input,ll s,ll e,char ch){

    if(s==e){
        if(input[s]==ch)return 0;
        return 1;
    }

    ll mid = s+(e-s)/2 ;//3
    return min((getCost(input,s,mid,ch)+ solve(input,mid+1,e,ch+1) ) ,
    (getCost(input,mid+1,e,ch) + solve(input,s,mid,ch+1)) );
}

int main() {
    ios_base::sync_with_stdio(false) ;
    ll t ;
    cin>>t ;
    while(t--){
        ll n ;
        cin>>n ;
        string s ;
        cin>>s ;

        cout<<solve(s,0,n-1,'a')<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll getCost(string input,ll s,ll e,char ch){
    ll cost = 0;
    for(ll i=s;i<=e;i++){
        if(input[i]!=ch)cost++ ;
    }

    return cost;
}

ll solve(string input,ll s,ll e,char ch){

    if(s==e){
        if(input[s]==ch)return 0;
        return 1;
    }

    ll mid = s+(e-s)/2 ;//3
    return min((getCost(input,s,mid,ch)+ solve(input,mid+1,e,ch+1) ) ,
    (getCost(input,mid+1,e,ch) + solve(input,s,mid,ch+1)) );
}

int main() {
    ios_base::sync_with_stdio(false);
    ll t ;
    cin>>t ;
    while(t--){
        ll n ;
        cin>>n ;
        string s ;
        cin>>s ;

        cout<<solve(s,0,n-1,'a')<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

ll getCost(string& input,ll s,ll e,char ch){
    ll cost = 0;
    for(ll i=s;i<=e;i++){
        if(input[i]!=ch)cost++ ;
    }

    return cost;
}

ll solve(string& input,ll s,ll e,char ch){

    if(s==e){
        if(input[s]==ch)return 0;
        return 1;
    }

//    ll mid = s+(e-s)/2 ;//3

    ll mid = (s+e+1)/2 ;
    return min((getCost(input,s,mid-1,ch)+ solve(input,mid,e,ch+1) ) ,
    (getCost(input,mid,e,ch) + solve(input,s,mid-1,ch+1)) );
}

int main() {
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    ll t ;
    cin>>t ;
    while(t--){
        ll n ;
        cin>>n ;
        string s ;
        cin>>s ;

        cout<<solve(s,0,n-1,'a')<<endl;

    }
}


/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>

typedef long long ll;

using namespace std;

int ch(string & s,int l , int r, char c){

    if((r-l ) == 1)return (c==s[l])?0:1;//base case

    int a= r-l;
    a/=2;
    int cost1 = 0,cost2=0 ;
    // map<char, int> fre;
    int left = 0,right= 0;
    for(int i = l ; i< l+a; i++){
        // fre[s[i]]++; //later i will collect max frequency :)
        if(s[i] == c)left++;
    }

    // fre.clear();
    for(int i = a+l ; i< r; i++){
        // fre[s[i]]++; //later i will collect max frequency :)
        // right  = max(right,fre[s[i]]);
        if(s[i] == c)right++;
    }

        cost1 += a-left;
        cost1 += ch(s, l+a, r, c+1);

        cost2 += a - right;
        cost2 += ch(s, l , l+a , c+1);  //begin end format

    return min(cost1,cost2);

}

int main() {
    // your code goes here
    ll tc,n;

    cin>>tc;
    while(tc--) {

        cin>>n;
        string s;

        cin>>s;

        int cost = ch(s,0,n,'a');

        cout<<cost<<"\n";
    }
    return 0;
}
//
// Created by yozaam on 13/06/20.
//


#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

int getCost(string &s,int start,int end,const char& good){
    int cost = 0;
    for(int i=start;i<=end;i++){
        if(s[i]!=good)cost++ ;
    }

    return cost ;
}

int solve(string& s,int start,int end,char good){
    if(start>end)return 0;
    if(start==end){
        if(s[start]==good)return 0;
        return 1;
    }

    int mid =(start+end)/2 ;

    return min(getCost(s,start,mid,good)+solve(s,mid+1,end,good+1) , getCost(s,mid+1,end,good)+solve(s,start,mid,good+1));
}

int main() {
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    ll t ;
    cin>>t ;
    while(t--){
        ll n ;
        cin>>n ;
        string s ;
        cin>>s ;

        cout<<solve(s,0,n-1,'a')<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

ll getCost(string input,ll s,ll e,char ch){
    ll cost = 0;
    for(ll i=s;i<=e;i++){
        if(input[i]!=ch)cost++ ;
    }

    return cost;
}

ll solve(string input,ll s,ll e,char ch){

    if(s==e){
        if(input[s]==ch)return 0;
        return 1;
    }

//    ll mid = s+(e-s)/2 ;//3

    ll mid = (s+e+1)/2 ;
    return min((getCost(input,s,mid-1,ch)+ solve(input,mid,e,ch+1) ) ,
    (getCost(input,mid,e,ch) + solve(input,s,mid-1,ch+1)) );
}

int main() {
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    ll t ;
    cin>>t ;
    while(t--){
        ll n ;
        cin>>n ;
        string s ;
        cin>>s ;

        cout<<solve(s,0,n-1,'a')<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

ll getCost(const string input,ll s,ll e,char ch){
    ll cost = 0;
    for(ll i=s;i<=e;i++){
        if(input[i]!=ch)cost++ ;
    }

    return cost;
}

ll solve(const string input,ll s,ll e,char ch){

    if(s==e){
        if(input[s]==ch)return 0;
        return 1;
    }

//    ll mid = s+(e-s)/2 ;//3

    ll mid = (s+e+1)/2 ;
    return min((getCost(input,s,mid-1,ch)+ solve(input,mid,e,ch+1) ) ,
    (getCost(input,mid,e,ch) + solve(input,s,mid-1,ch+1)) );
}

int main() {
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    ll t ;
    cin>>t ;
    while(t--){
        ll n ;
        cin>>n ;
        string s ;
        cin>>s ;

        cout<<solve(s,0,n-1,'a')<<endl;

    }
}


#include <bits/stdc++.h>
using namespace std;

int getCost(string input,int s,int e,char ch){
    int cost = 0;
    for(int i=s;i<=e;i++){
        if(input[i]!=ch)cost++ ;
    }

    return cost;
}

int solve(string input,int s,int e,char ch){

    if(s==e){
        if(input[s]==ch)return 0;
        return 1;
    }

    int mid = s+(e-s)/2 ;//3
    return min((getCost(input,s,mid,ch)+ solve(input,mid+1,e,ch+1) ) ,
    (getCost(input,mid+1,e,ch) + solve(input,s,mid,ch+1)) );
}

int main() {
    int t ;
    cin>>t ;
    while(t--){
        int n ;
        cin>>n ;
        string s ;
        cin>>s ;

        cout<<solve(s,0,n-1,'a')<<endl;

    }
}


#include <bits/stdc++.h>
using namespace std;

int getCost(string input,int s,int e,char ch){
    int cost = 0;
    for(int i=s;i<=e;i++){
        if(input[i]!=ch)cost++ ;
    }

    return cost;
}

int solve(string input,int s,int e,char ch){

    if(s==e){
        if(input[s]==ch)return 0;
        return 1;
    }

    int mid = s+(e-s)/2 ;//3
    return min((getCost(input,s,mid,ch)+ solve(input,mid+1,e,ch+1) ) ,
    (getCost(input,mid+1,e,ch) + solve(input,s,mid,ch+1)) );
}

int main() {
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t ;
    cin>>t ;
    while(t--){
        int n ;
        cin>>n ;
        string s ;
        cin>>s ;

        cout<<solve(s,0,n-1,'a')<<endl;

    }
}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)2e5+5;
const int mod = (int)1e9+7;

string s;
int diff[M][26];

int func(int l, int r, char c)
{
	if(l == r) return (s[l] != c);
	int mid = (r+l-1)/2, cnt1, cnt2, ind = (int)(c-'a');
	cnt1 = diff[mid][ind] - diff[l-1][ind];
	cnt2 = diff[r][ind] - diff[mid][ind];
	c++;
	return min(cnt1+func(mid+1, r, c), cnt2+func(l, mid, c));
}

void solve()
{
	int n;
	char c = 'a';
	cin>>n>>s;
	s = "@"+s;
	set <int> st;
	f(i, 0, n+1) f(j, 0, 26) diff[i][j] = 0;
	f(j, 0, 26)
	{
		f(i, 0, n) diff[i+1][j] = diff[i][j] + (s[i+1] != c);
		c++;
	}
	cout<<func(1, n, 'a')<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M1 = (int)20;
const int M2 = (int)2e5+5;
const int mod = (int)1e9+7;

string s;
int dp[M2][M1][M1], mp[M2], diff[M2][26];

int func(int l, int r, char c)
{
	if(l == r) return (s[l] != c);
	if(dp[l][mp[l]][mp[r]] != -1) return dp[l][mp[l]][mp[r]];
	int mid = (r+l-1)/2, cnt1, cnt2, ind = (int)(c-'a');
	cnt1 = diff[mid][ind] - diff[l-1][ind];
	cnt2 = diff[r][ind] - diff[mid][ind];
	c++;
	return dp[l][mp[l]][mp[r]] = min(cnt1+func(mid+1, r, c), cnt2+func(l, mid, c));
}

void solve()
{
	int n;
	char c = 'a';
	cin>>n>>s;
	s = "@"+s;
	set <int> st;
	f(i, 1, n+1) mp[i] = (int)log2(i), st.insert(mp[i]);
	f(i, 0, n+1) f(j, 0, 26) diff[i][j] = 0;
	f(i, 0, n+1) for(auto x : st) for(auto y : st) dp[i][x][y] = -1;
	f(j, 0, 26)
	{
		f(i, 0, n) diff[i+1][j] = diff[i][j] + (s[i+1] != c);
		c++;
	}
	cout<<func(1, n, 'a')<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M1 = (int)1005;
const int M2 = (int)2e5+5;
const int mod = (int)1e9+7;

string s;
int dp[M1][M1], mp[M2], diff[M2][26];

int func(int l, int r, char c)
{
	if(l == r) return (s[l] != c);
	if(dp[mp[l]][mp[r]] != -1) return dp[mp[l]][mp[r]];
	int mid = (r+l-1)/2, cnt1, cnt2, ind = c-'a';
	cnt1 = diff[mid][ind] - diff[l-1][ind];
	cnt2 = diff[r][ind] - diff[mid][ind];
	// cout<<l<<' '<<mid<<' '<<r<<endl;
	c++;
	// cout<<cnt1<<' '<<cnt2<<' '<<c<<endl;
	int m1 = cnt1 + func(mid+1, r, c);
	int m2 = cnt2 + func(l, mid, c);
	return dp[mp[l]][mp[r]] = min(m1, m2);
}

void solve()
{
	int n;
	char c = 'a';
	cin>>n>>s;
	s = "@"+s;
	set <int> st;
	f(i, 1, n+1) mp[i] = (int)log2(i), st.insert(mp[i]);
	f(i, 0, n+1) f(j, 0, 26) diff[i][j] = 0;
	for(auto x : st) for(auto y : st) dp[x][y] = -1;
	f(j, 0, 26)
	{
		f(i, 0, n) diff[i+1][j] = diff[i][j] + (s[i+1] != c);
		c++;
	}
	cout<<func(1, n, 'a')<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M1 = (int)1005;
const int M2 = (int)2e5+5;
const int mod = (int)1e9+7;

string s;
int dp[M1][M1], mp[M2], diff[M2][26];

int func(int l, int r, char c)
{
	if(l == r) return (s[l] != c);
	if(dp[mp[l]][mp[r]] != -1) return dp[mp[l]][mp[r]];
	int mid = (r+l-1)/2, cnt1, cnt2, ind = c-'a';
	cnt1 = diff[mid][ind] - diff[l-1][ind];
	cnt2 = diff[r][ind] - diff[mid][ind];
	c++;
	return dp[mp[l]][mp[r]] = min(cnt1 + func(mid+1, r, c), cnt2 + func(l, mid, c));
}

// void solve()
// {
// }

int32_t main()
{
    IOS
    int t = 1;
    cin>>t;
    f(tno, 1, t+1)
    {
		int n;
		char c = 'a';
		cin>>n>>s;
		if(tno == 152) cout<<s<<endl;
		s = "@"+s;
		set <int> st;
		f(i, 0, n+1) mp[i] = (int)log2(i), st.insert(mp[i]);
		f(i, 0, n+1) f(j, 0, 26) diff[i][j] = 0;
		for(auto x : st) for(auto y : st) dp[x][y] = -1;
		f(j, 0, 26)
		{
			f(i, 0, n) diff[i+1][j] = diff[i][j] + (s[i+1] != c);
			c++;
		}
		cout<<func(1, n, 'a')<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
// #define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M1 = (int)1005;
const int M2 = (int)2e5+5;
const int mod = (int)1e9+7;

string s;
int dp[M1][M1], mp[M2], diff[M2][26];

int func(int l, int r, char c)
{
	if(l == r) return (s[l] != c);
	if(dp[mp[l]][mp[r]] != -1) return dp[mp[l]][mp[r]];
	int mid = (r+l-1)/2, cnt1, cnt2, ind = c-'a';
	cnt1 = diff[mid][ind] - diff[l-1][ind];
	cnt2 = diff[r][ind] - diff[mid][ind];
	c++;
	return dp[mp[l]][mp[r]] = min(cnt1 + func(mid+1, r, c), cnt2 + func(l, mid, c));
}

void solve()
{
	int n;
	char c = 'a';
	cin>>n>>s;
	s = "@"+s;
	set <int> st;
	f(i, 0, n+1) mp[i] = (int)log2(i), st.insert(mp[i]);
	f(i, 0, n+1) f(j, 0, 26) diff[i][j] = 0;
	for(auto x : st) for(auto y : st) dp[x][y] = -1;
	f(j, 0, 26)
	{
		f(i, 0, n) diff[i+1][j] = diff[i][j] + (s[i+1] != c);
		c++;
	}
	cout<<func(1, n, 'a')<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)2e5+5;
const int mod = (int)1e9+7;

string s;
int dp[M][20], mp[M], diff[M][26];

int func(int l, int r, char c)
{
	if(l == r) return (s[l] != c);
	if(dp[l][mp[l]] != -1) return dp[l][mp[l]];
	int mid = (r+l-1)/2, cnt1, cnt2, ind = (int)(c-'a');
	cnt1 = diff[mid][ind] - diff[l-1][ind];
	cnt2 = diff[r][ind] - diff[mid][ind];
	c++;
	return dp[l][mp[l]] = min(cnt1+func(mid+1, r, c), cnt2+func(l, mid, c));
}

void solve()
{
	int n;
	char c = 'a';
	cin>>n>>s;
	s = "@"+s;
	set <int> st;
	f(i, 1, n+1) mp[i] = (int)log2(i), st.insert(mp[i]);
	f(i, 0, n+1) f(j, 0, 26) diff[i][j] = 0;
	f(i, 0, n+1) for(auto x : st) dp[i][x] = -1;
	f(j, 0, 26)
	{
		f(i, 0, n) diff[i+1][j] = diff[i][j] + (s[i+1] != c);
		c++;
	}
	cout<<func(1, n, 'a')<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M1 = (int)1005;
const int M2 = (int)2e5+5;
const int mod = (int)1e9+7;

string s;
int dp[M1][M1], mp[M2], diff[M2][26];

int func(int l, int r, char c)
{
	if(l == r) return (s[l] != c);
	if(dp[mp[l]][mp[r]] != -1) return dp[mp[l]][mp[r]];
	int mid = (r+l-1)/2, cnt1, cnt2, ind = c-'a';
	cnt1 = diff[mid][ind] - diff[l-1][ind];
	cnt2 = diff[r][ind] - diff[mid][ind];
	c++;
	return dp[mp[l]][mp[r]] = min(cnt1 + func(mid+1, r, c), cnt2 + func(l, mid, c));
}

void solve()
{
	int n;
	char c = 'a';
	cin>>n>>s;
	s = "@"+s;
	set <int> st;
	f(i, 0, n+1) mp[i] = (int)log2(i), st.insert(mp[i]);
	f(i, 0, n+1) f(j, 0, 26) diff[i][j] = 0;
	for(auto x : st)
	{
		for(auto y : st) dp[x][y] = -1;
	}
	f(j, 0, 26)
	{
		f(i, 0, n) diff[i+1][j] = diff[i][j] + (s[i+1] != c);
		c++;
	}
	cout<<func(1, n, 'a')<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M1 = (int)1005;
const int M2 = (int)2e5+5;
const int mod = (int)1e9+7;

string s;
int dp[M1][M1], mp[M2], diff[M2][26];

int func(int l, int r, char c)
{
	if(l == r) return (s[l] != c);
	if(dp[mp[l]][mp[r]] != -1) return dp[mp[l]][mp[r]];
	int mid = (r+l-1)/2, cnt1, cnt2, ind = c-'a';
	cnt1 = diff[mid][ind] - diff[l-1][ind];
	cnt2 = diff[r][ind] - diff[mid][ind];
	c++;
	return dp[mp[l]][mp[r]] = min(cnt1 + func(mid+1, r, c), cnt2 + func(l, mid, c));
}

void solve()
{
	int n;
	char c = 'a';
	cin>>n>>s;
	s = "@"+s;
	set <int> st;
	f(i, 1, n+1) mp[i] = (int)log2(i), st.insert(mp[i]);
	f(i, 0, n+1) f(j, 0, 26) diff[i][j] = 0;
	for(auto x : st) for(auto y : st) dp[x][y] = -1;
	f(j, 0, 26)
	{
		f(i, 0, n) diff[i+1][j] = diff[i][j] + (s[i+1] != c);
		c++;
	}
	cout<<func(1, n, 'a')<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M1 = (int)1005;
const int M2 = (int)2e5+5;
const int mod = (int)1e9+7;

string s;
int dp[M1][M1], mp[M2], diff[M2][26];

int func(int l, int r, char c)
{
	if(l == r) return (s[l] != c);
	if(dp[mp[l]][mp[r]] != -1) return dp[mp[l]][mp[r]];
	int mid = (r+l-1)/2, cnt1, cnt2, ind = c-'a';
	cnt1 = diff[mid][ind] - diff[l-1][ind];
	cnt2 = diff[r][ind] - diff[mid][ind];
	c++;
	return dp[mp[l]][mp[r]] = min(cnt1 + func(mid+1, r, c), cnt2 + func(l, mid, c));
}

void solve()
{
	int n;
	char c = 'a';
	cin>>n>>s;
	s = "@"+s;
	set <int> st;
	f(i, 0, n+1) mp[i] = (int)log2(i), st.insert(mp[i]);
	f(i, 0, n+1) f(j, 0, 26) diff[i][j] = 0;
	for(auto x : st) for(auto y : st) dp[x][y] = -1;
	f(j, 0, 26)
	{
		f(i, 0, n) diff[i+1][j] = diff[i][j] + (s[i+1] != c);
		c++;
	}
	cout<<func(1, n, 'a')<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)1005;
const int mod = (int)1e9+7;

string s;
int dp[M][M], mp[M*M];

int func(int l, int r, char c)
{
	if(l == r) return (s[l] != c);
	if(dp[mp[l]][mp[r]] != -1) return dp[mp[l]][mp[r]];
	int mid = (r+l-1)/2, cnt1 = 0, cnt2 = 0;
	f(i, l, mid+1) cnt1 += (s[i] != c);
	f(i, mid+1, r+1) cnt2 += (s[i] != c);
	c++;
	return dp[mp[l]][mp[r]] = min(cnt1 + func(mid+1, r, c), cnt2 + func(l, mid, c));
}

void solve()
{
	int n;
	cin>>n>>s;
	s = "@"+s;
	memset(dp, -1, sizeof dp);
	f(i, 0, n+1) mp[i] = (int)log2(i);
	cout<<func(1, n, 'a')<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ff(n,m) for(ll i=1;i<n;i++)for(ll j=1;j<m;j++)
#define f(m) for(ll i=0;i<m;i++)
using namespace std;

ll tomakegood(string s,string d,ll k,ll srt,ll ed,ll m)
{
    ll cnt1=0,cnt2=0;
    if(k==1){if(s[srt]!=d[m]){return 1;}else{return 0;}}
    for(ll i=srt;i<srt+k/2;i++)
        {if(s[i]!=d[m]){cnt1++;}}
    for(ll i=srt+k/2;i<ed;i++)
        {if(s[i]!=d[m]){cnt2++;}}//cout<<cnt1<<" "<<cnt2<<endl;
    return min(cnt1+tomakegood(s,d,k/2,srt+k/2,ed,m+1),cnt2+tomakegood(s,d,k/2,srt,srt+k/2,m+1));

}

int main()
{
    fio;
    ll t;
    cin>>t;
    ll l;
    string s;
    string d="abcdefghijklmnopqrstuvwxyz";
    while(t--)
    {
        cin>>l>>s;
        cout<<tomakegood(s,d,l,0,l,0)<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ff(n,m) for(ll i=1;i<n;i++)for(ll j=1;j<m;j++)
#define f(m) for(ll i=0;i<m;i++)
using namespace std;

ll tomakegood(string s,string d,ll k,ll srt,ll ed,ll m)
{
    ll cnt1=0,cnt2=0;
    if(k==1){if(s[srt]!=d[m]){return 1;}else{return 0;}}
    for(ll i=srt;i<srt+k/2;i++)
        {if(s[i]!=d[m]){cnt1++;}}
    for(ll i=srt+k/2;i<ed;i++)
        {if(s[i]!=d[m]){cnt2++;}}
    if(cnt1==0){return cnt1+tomakegood(s,d,k/2,srt+k/2,ed,m+1);}
    if(cnt2==0){return cnt2+tomakegood(s,d,k/2,srt,srt+k/2,m+1);}
    return min(cnt1+tomakegood(s,d,k/2,srt+k/2,ed,m+1),cnt2+tomakegood(s,d,k/2,srt,srt+k/2,m+1));

}

int main()
{
    fio;
    ll t;
    cin>>t;
    ll l;
    string s;
    string d="abcdefghijklmnopqrstuvwxyz";
    while(t--)
    {
        cin>>l>>s;
        cout<<tomakegood(s,d,l,0,l,0)<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ff(n,m) for(ll i=1;i<n;i++)for(ll j=1;j<m;j++)
#define f(m) for(ll i=0;i<m;i++)
using namespace std;

ll tomakegood(string s,string d,ll k,ll srt,ll ed,ll m)
{    //cout<<d[m]<<endl;
     //cout<<srt<<" "<<ed<<endl;
    ll cnt1=0,cnt2=0;
    if(k==1){if(s[srt]!=d[m]){return 1;}else{return 0;}}
   // if(k==2){if(s[srt]==}
    for(ll i=srt;i<srt+k/2;i++)
        {if(s[i]!=d[m]){cnt1++;}}
    for(ll i=srt+k/2;i<ed;i++)
        {if(s[i]!=d[m]){cnt2++;}}//cout<<cnt1<<" "<<cnt2<<endl;
    if(cnt1<cnt2){return (cnt1+tomakegood(s,d,k/2,srt+k/2,ed,m+1));}
    else if(cnt1>cnt2){return (cnt2+tomakegood(s,d,k/2,srt,srt+k/2,m+1));}
    else{return cnt1+min(tomakegood(s,d,k/2,srt+k/2,ed,m+1),(tomakegood(s,d,k/2,srt,srt+k/2,m+1)));}

}

int main()
{
    fio;
    ll t;
    cin>>t;
    ll l;
    string s;
    string d="abcdefghijklmnopqrstuvwxyz";
    while(t--)
    {
        cin>>l>>s;
        cout<<tomakegood(s,d,l,0,l,0)<<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ff(n,m) for(ll i=1;i<n;i++)for(ll j=1;j<m;j++)
#define f(m) for(ll i=0;i<m;i++)
using namespace std;

ll tomakegood(string s,ll srt,ll ed,char c)
{//cout<<srt<<" "<<ed<<endl;
    ll cnt1=0,cnt2=0;
    ll k=ed-srt;
    if(srt==ed-1){if(s[srt]!=c){return 1;}else{return 0;}}
    for(ll i=srt;i<srt+k/2;i++)
        {if(s[i]!=c){cnt1++;}}
    for(ll i=srt+k/2;i<ed;i++)
        {if(s[i]!=c){cnt2++;}}
    if(cnt1==0){return cnt1+tomakegood(s,srt+k/2,ed,c+1);}
    if(cnt2==0){return cnt2+tomakegood(s,srt,srt+k/2,c+1);}
    return min(cnt1+tomakegood(s,srt+k/2,ed,c+1),cnt2+tomakegood(s,srt,srt+k/2,c+1));

}

int main()
{
    fio;
    ll t;
    cin>>t;
    ll l;
    string s;
    char a='a';
    while(t--)
    {
        cin>>l>>s;

        cout<<tomakegood(s,0,l,a)<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ff(n,m) for(ll i=1;i<n;i++)for(ll j=1;j<m;j++)
#define f(m) for(ll i=0;i<m;i++)
using namespace std;

ll tomakegood(string s,string d,ll k,ll srt,ll ed,ll m)
{   //cout<<k<<endl;
    //cout<<srt<<" "<<ed<<endl;
    ll cnt1=0,cnt2=0;
    if(k==1){if(s[srt]!=d[m]){return 1;}else{return 0;}}
    for(ll i=srt;i<srt+k/2;i++)
        {if(s[i]!=d[m]){cnt1++;}}
    for(ll i=srt+k/2;i<ed;i++)
        {if(s[i]!=d[m]){cnt2++;}}
    if(cnt1<cnt2){return (cnt1+tomakegood(s,d,k/2,srt+k/2,ed,m+1));}
    else if(cnt1>cnt2){return (cnt2+tomakegood(s,d,k/2,srt,srt+k/2,m+1));}
    else{return cnt1+min(tomakegood(s,d,k/2,srt+k/2,ed,m+1),(cnt2+tomakegood(s,d,k/2,srt,srt+k/2,m+1)));}

}

int main()
{
    fio;
    ll t;
    cin>>t;
    ll l;
    string s;
    string d="abcdefghijklmnopqrstuvwxyz";
    while(t--)
    {
        cin>>l>>s;
        if(l==1)
        {
            if(s[0]!='a'){cout<<1<<endl;}
            else{cout<<0<<endl;}
            continue;
        }
        cout<<tomakegood(s,d,l,0,l,0)<<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ff(n,m) for(ll i=1;i<n;i++)for(ll j=1;j<m;j++)
#define f(m) for(ll i=0;i<m;i++)
using namespace std;

ll tomakegood(string s,ll srt,ll ed,char c)
{   //cout<<srt<<" "<<ed<<endl;
    ll cnt1=0,cnt2=0;
    ll k=ed-srt+1;
    if(srt==ed){if(s[srt]!=c){return 1;}else{return 0;}}
    for(ll i=srt;i<srt+k/2;i++)
        {if(s[i]!=c){cnt1++;}}
    for(ll i=srt+k/2;i<=ed;i++)
        {if(s[i]!=c){cnt2++;}}
    if(cnt1==0){return cnt1+tomakegood(s,srt+k/2,ed,c+1);}
    if(cnt2==0){return cnt2+tomakegood(s,srt,srt+(k/2)-1,c+1);}
    return min(cnt1+tomakegood(s,srt+k/2,ed,c+1),cnt2+tomakegood(s,srt,srt+(k/2)-1,c+1));

}

int main()
{
    fio;
    ll t;
    cin>>t;
    ll l;
    string s;
    char a='a';
    while(t--)
    {
        cin>>l>>s;
        cout<<tomakegood(s,0,l-1,a)<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ff(n,m) for(ll i=1;i<n;i++)for(ll j=1;j<m;j++)
#define f(m) for(ll i=0;i<m;i++)
using namespace std;

ll tomakegood(char s[],string d,ll k,ll srt,ll ed,ll m)
{
    ll cnt1=0,cnt2=0;
    if(k==1){if(s[srt]!=d[m]){return 1;}else{return 0;}}
    for(ll i=srt;i<srt+k/2;i++)
        {if(s[i]!=d[m]){cnt1++;}}
    for(ll i=srt+k/2;i<ed;i++)
        {if(s[i]!=d[m]){cnt2++;}}//cout<<cnt1<<" "<<cnt2<<endl;
    return min(cnt1+tomakegood(s,d,k/2,srt+k/2,ed,m+1),cnt2+tomakegood(s,d,k/2,srt,srt+k/2,m+1));

}

int main()
{
    fio;
    ll t;
    cin>>t;
    ll l;
    string d="abcdefghijklmnopqrstuvwxyz";
    while(t--)
    {
        cin>>l;
        char s[l];
        cin>>s;
        cout<<tomakegood(s,d,l,0,l,0)<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ff(n,m) for(ll i=1;i<n;i++)for(ll j=1;j<m;j++)
#define f(m) for(ll i=0;i<m;i++)
using namespace std;

ll tomakegood(char s[],ll srt,ll ed,char c)
{   //cout<<srt<<" "<<ed<<endl;
    ll cnt1=0,cnt2=0;
    ll k=ed-srt+1;
    if(srt==ed){if(s[srt]!=c){return 1;}else{return 0;}}
    for(ll i=srt;i<srt+k/2;i++)
        {if(s[i]!=c){cnt1++;}}
    for(ll i=srt+k/2;i<=ed;i++)
        {if(s[i]!=c){cnt2++;}}
    if(cnt1==0){return cnt1+tomakegood(s,srt+k/2,ed,c+1);}
    if(cnt2==0){return cnt2+tomakegood(s,srt,srt+(k/2)-1,c+1);}
    return min(cnt1+tomakegood(s,srt+k/2,ed,c+1),cnt2+tomakegood(s,srt,srt+(k/2)-1,c+1));

}

int main()
{
    fio;
    ll t;
    cin>>t;
    ll l;
    char a='a';
    while(t--)
    {
        cin>>l;
        char s[l];
        cin>>s;
        cout<<tomakegood(s,0,l-1,a)<<endl;

    }
    return 0;
}


/* Manish Pant - insider_pants */

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

#define F first
#define S second
#define endl "\n"
#define pb push_back
typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int rec(int l, int r, char c, string &s)
{
    if(l == r)
    {
        if(s[l] == c)
            return 0;
        else
            return 1;
    }

    int mid = (l + r) >> 1;

    int c1 = 0, c2 = 0;
    for(int i = l; i <= mid; i++)
        c1 += (s[i] != c);
    for(int i = mid + 1; i <= r; i++)
        c2 += (s[i] != c);

    c2 += rec(l, mid, c + 1, s);
    c1 += rec(mid + 1, r, c + 1, s);

    return min(c1, c2);
}

void solve()
{
    int n; cin >> n;
    string s; cin >> s;

    cout << rec(0, n - 1, 'a', s) << endl;
}

int main()
{
    fast();
    int t; cin >> t;
    while(t--)
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,(b),sizeof(a))
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define all(cont) cont.begin(),cont.end()
#define rall(cont) cont.rbegin(),cont.rend()
#define mp make_pair
#define pb push_back
typedef long long ll;
#define MOD 1000000007
ll gcd(ll a,ll b){if (b == 0)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;if(x==0)return 0;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res%MOD;}
void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int func(string s, char ch, int l, int r){
    if(l == r){
        if(ch != s[l])return 1;
        return 0;
    }

    int mid = (l+r) / 2;
    int leftReplacements = 0;
    for(int i=l;i<=mid;i++){
        if(s[i] != ch)leftReplacements++;
    }
    int rightReplacements = 0;
    for(int i= mid+1; i<=r; i++){
        if(s[i] != ch)rightReplacements++;
    }

    leftReplacements += func(s,ch+1, mid+1, r) ;
    rightReplacements += func(s,ch+1,l,mid);
    return min(leftReplacements, rightReplacements);
}

void solve(){
    int n; cin>>n;
    string s; cin>>s;
    cout<<func(s,'a', 0, n-1)<<endl;
}

int main(){
fast();
int t;
cin>>t;
// t=1;
while(t--){
    solve();
}
}


#include<bits/stdc++.h>
using namespace std;

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int func(string s, char ch, int l, int r){
    if(l == r){
        if(ch != s[l])return 1;
        return 0;
    }

    int mid = (l+r) / 2;
    int leftReplacements = 0;
    for(int i=l;i<=mid;i++){
        if(s[i] != ch)leftReplacements++;
    }
    int rightReplacements = 0;
    for(int i= mid+1; i<=r; i++){
        if(s[i] != ch)rightReplacements++;
    }

    leftReplacements += func(s,ch+1, mid+1, r) ;
    rightReplacements += func(s,ch+1,l,mid);
    return min(leftReplacements, rightReplacements);
}

void solve(){
    int n; cin>>n;
    string s; cin>>s;
    cout<<func(s,'a', 0, n-1)<<endl;
}

int main(){
fast();
int t;
cin>>t;
// t=1;
while(t--){
    solve();
}
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mem(a,b) memset(a,(b),sizeof(a))
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define all(cont) cont.begin(),cont.end()
#define rall(cont) cont.rbegin(),cont.rend()
#define mp make_pair
#define pb push_back
typedef long long ll;
#define MOD 1000000007
ll gcd(ll a,ll b){if (b == 0)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;if(x==0)return 0;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res%MOD;}

int func(string s, char ch, int l, int r){

    if(l == r){
        if(ch != s[l])return 1;
        return 0;
    }

    int mid = (l+r)/2;
    int leftReplacements = 0;
    rep(i,l,mid){
        if(s[i] != ch)leftReplacements++;
    }
    int rightReplacements = 0;
    rep(i,mid+1,r){
        if(s[i] != ch)rightReplacements++;
    }

    int a = func(s,ch+1, mid+1, r) + leftReplacements;
    int b = func(s,ch+1,l,mid) + rightReplacements;
    return min(a,b);
}

void solve(){
    int n; cin>>n;
    string s; cin>>s;
    int ans = func(s,'a', 0, n-1);
    cout<<ans<<endl;
}

int main(){
    fastio;
int t;
cin>>t;
// t=1;
while(t--){
    solve();
}
}


/* Manish Pant - insider_pants */

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

#define F first
#define S second
#define endl "\n"
#define pb push_back
typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int rec(int l, int r, char c, string &s)
{
    if(l == r)
    {
        if(s[l] == c)
            return 0;
        else
            return 1;
    }

    int mid = (l + r) >> 1;

    int c1 = 0, c2 = 0;
    for(int i = l; i <= mid; i++)
        c1 += (s[i] != c);
    for(int i = mid + 1; i <= r; i++)
        c2 += (s[i] != c);

    c2 += rec(l, mid, c + 1, s);
    c1 += rec(mid + 1, r, c + 1, s);

    return min(c1, c2);
}
//cdbnicdcvjdnv
void solve()
{
    int n; cin >> n;
    string s; cin >> s;

    cout << rec(0, n - 1, 'a', s) << endl;
}

int main()
{
    fast();
    int t; cin >> t;
    while(t--)
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int func(string s, char ch, int l, int r){
    if(l == r){
        if(ch != s[l])return 1;
        return 0;
    }

    int mid = (l+r) / 2;
    int leftReplacements = 0;
    for(int i=l;i<=mid;i++){
        if(s[i] != ch)leftReplacements++;
    }
    int rightReplacements = 0;
    for(int i= mid+1; i<=r; i++){
        if(s[i] != ch)rightReplacements++;
    }

    leftReplacements += func(s,ch+1, mid+1, r) ;
    rightReplacements += func(s,ch+1,l,mid);
    return min(leftReplacements, rightReplacements);
}

void solve(){
    int n; cin>>n;
    string s; cin>>s;
    cout<<func(s,'a', 0, n-1)<<endl;
}

int main(){
fast();
int t;
cin>>t;
// t=1;
while(t--){
    solve();
}
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int func(string &s, char ch, int l, int r){
    if(l == r){
        if(ch != s[l])return 1;
        else return 0;
    }

    int mid = (l+r) >> 1;
    int leftReplacements = 0;
    for(int i=l;i<=mid;i++){
        if(s[i] != ch)leftReplacements++;
    }
    int rightReplacements = 0;
    for(int i= mid+1; i<=r; i++){
        if(s[i] != ch)rightReplacements++;
    }

    leftReplacements += func(s,ch+1, mid+1, r) ;
    rightReplacements += func(s,ch+1,l,mid);
    return min(leftReplacements, rightReplacements);
}

void solve(){
    int n; cin>>n;
    string s; cin>>s;
    cout<<func(s,'a', 0, n-1)<<endl;
}

int main(){
fast();
int t;
cin>>t;
// t=1;
while(t--){
    solve();
}
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int func(string s, char ch, int l, int r){
    if(l == r){
        if(ch != s[l])return 1;
        return 0;
    }

    int mid = (l+r) >> 1;
    int leftReplacements = 0;
    for(int i=l;i<=mid;i++){
        if(s[i] != ch)leftReplacements++;
    }
    int rightReplacements = 0;
    for(int i= mid+1; i<=r; i++){
        if(s[i] != ch)rightReplacements++;
    }

    leftReplacements += func(s,ch+1, mid+1, r) ;
    rightReplacements += func(s,ch+1,l,mid);
    return min(leftReplacements, rightReplacements);
}

void solve(){
    int n; cin>>n;
    string s; cin>>s;
    cout<<func(s,'a', 0, n-1)<<endl;
}

int main(){
fast();
int t;
cin>>t;
// t=1;
while(t--){
    solve();
}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vll vector<ll>
int call(string s,ll start,ll end,char c)
{
    if(start>end)
    {
        return 0;
    }
    if(start==end)
    {
        if(s[start]!=c)
        {
            return 1;
        }
        return 0;
    }
    ll mid=start+(end-start)/2;
    ll p=0,q=0,r=0,l=0;
    for(ll i=start;i<=mid;i++)
    {
        if(s[i]!=c) p++;
    }
    //q=call(s,mid+1,end,c+1);
    for(ll i=mid+1;i<=end;i++)
    {
        if(s[i]!=c) r++;
    }
    //l=call(s,start,mid,c+1);
    return min(p+call(s,mid+1,end,c+1),r+call(s,start,mid,c+1));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        //int x=0;
        ll c=call(s,0,n-1,'a');
        cout<<c<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vll vector<ll>
//string s;
ll call(ll start,ll end,char c)
{
    if(start>end)
    {
        return 0;
    }
    if(start==end)
    {
        if(s[start]!=c)
        {
            return 1;
        }
        return 0;
    }
    ll mid=start+(end-start)/2;
    ll p=0,r=0;
    for(ll i=start;i<=mid;i++)
    {
        if(s[i]!=c) p++;
    }
    for(ll i=mid+1;i<=end;i++)
    {
        if(s[i]!=c) r++;
    }
    return min(p+call(mid+1,end,c+1),r+call(start,mid,c+1));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        //int x=0;
        ll c=call(0,n-1,'a');
        cout<<c<<endl;
    }
}


a,b,n = map(int,input().split())
ans = "No solution"

if a == 0 and b == 0:
    ans =5
elif a == 0 and b!= 0:
    ans
elif a != 0 and b == 0:
    ans = 0
elif b%a != 0:
    ans
else:
    a = b / a
    if a < 0 :
        a = abs(a)
        b = 0
    for i in range(1001):
        if i ** n == a:
            ans = i

    if b == 0 :ans = - ans

print(ans)


a,b,n = map(int,input().split())
ans = "No solution"

if a == 0 and b == 0:
    ans =5
elif a == 0 and b!= 0:
    ans
elif a != 0 and b == 0:
    ans = 0
else:
    a = b / a
    if a < 0 :
        a = abs(a)
        b = 0
    for i in range(1001):
        if i ** n == a:
            ans = i

    if b == 0 :ans = - ans

print(ans)


a,b,n = map(int,input().split())
ans = "No solution"
if a== 0:
    ans
elif b == 0:
    ans = 5
else:
    a = b / a
    if a < 0 :
        a = abs(a)
        b = 0
    for i in range(1000):
        if i ** n == a:
            ans = i

    if b == 0 :ans = - ans

print(ans)


a,b,n = map(int,input().split())
ans = "No solution"

if a == 0 and b == 0:
    ans =5
elif a == 0 and b!= 0:
    ans
elif a != 0 and b == 0:
    ans = 0
else:
    a = b / a
    if a < 0 :
        a = abs(a)
        b = 0
    for i in range(1000):
        if i ** n == a:
            ans = i

    if b == 0 :ans = - ans

print(ans)


import sys
a,b,n = map(int,input().split())

for i in range(-1000,1001):
    if a*(i**n)== b:
        print(i)
        sys.exit()
print("No solution")


import sys
a,b,n = map(int,input().split())

for i in range(-1000,1001):
    if a*(i**n)== b:
        print(i)
        sys.exit()
print("No soloution")


A,B,n=map(int,input().split())

if(A==0 and B==0):
    print(5)
elif(A==0):
    print("No solution")

elif((B/A)%1!=0):
    print("No solution")
else:

    v=B//A

    if(v<0):
        x=-1
    else:
        x=1
    v=pow(abs(v),1/n)
    vv=round(v)
    if(abs(vv-v)>(10**(-6))):
        print("No solution")
    else:
        print(x*int(vv))


A,B,n=map(int,input().split())

if(A==0):
    print(5)

elif((B/A)%1!=0):
    print(("No solution"))
else:

    v=B//A

    if(v<0):
        x=-1
    else:
        x=1
    v=pow(abs(v),1/n)
    if(int(v)!=v):
        print("No solution")
    else:
        print(x*int(v))


A,B,n=map(int,input().split())

if(A==0 and B==0):
    print(5)
elif(A==0):
    print("No solution")

elif((B/A)%1!=0):
    print("No solution")
else:

    v=B//A

    if(v<0):
        x=-1
    else:
        x=1
    v=pow(abs(v),1/n)
    if(int(v)!=v):
        print("No solution")
    else:
        print(x*int(v))


l=list(map(int,input().split()))
A,B,n=l[0],l[1],l[2]
if A==0 and B==0:
    print('5')
elif A==0 and B!=0:
    print('No solution')

elif A!=0 and B==0:
    print('0')

elif (B/A).is_integer():
    c=int(B/A)

    e=abs(c)

    f=e**(1/n)

    if (f).is_integer() :

        if c<0:
            print(-int(f))
        else:
            print(int(f))
    elif (int(f)+1)-f<10**(-3):
        if c<0:
            print(-(int(f)+1))
        else:
            print(int(f)+1)
    else:
        print('No solution')
else:
    print('No solution')