#include <bits/stdc++.h>
#define int long long
#define YES cout<<"YES\n";return;
#define NO cout<<"NO\n";return;
#define write(a) cout<<a<<"\n";return;
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);
    long long powmod(long long a,long long b,long long mod) {
        if (b==0 || a==1)  {if (mod==1) return 0; else return 1; }

        if (b%2==0) { long long k=powmod(a,b/2,mod); return (k*k)%mod; }
        else {long long k=powmod(a,b/2,mod); return ( (k*k) %mod *a)% mod; }
    }
    long long gcd(long long a, long long b) {
        if (a==0) return b;
        if (b==0) return a;
        if (a>b) return gcd(a%b,b); else return gcd(b%a,a);
    }
      int prime(int p) { // 1 - простое
        for (int i=2;i*i<=p;i++) {
            if (p%i==0 && i<p) return i;
        }
        return 1;
    }

     int inv(int a, int mod) {
        return powmod(a,mod-2,mod);
    }

  int random_modul() {

    uniform_int_distribution <int> u1(1e9, 2e9);
    int pepega=u1(rnd);
    while (prime(pepega)!=1) pepega=u1(rnd);
    return pepega;
}

    void solve () {

         /* --------- */

         int a;
         cin>>a;
         int m[a];
         for (int i=0;i<a;i++) cin>>m[i];
         int left=1;
         int d=0;
         int leaf=1;
         int cur=0;
         for (int i=1;i<a;i++) {
             if (i==1) { leaf--; cur++; }
            else {
                if (m[i]>m[i-1]) {cur++; }
                else {  if (leaf<=0) { d++; leaf=cur;   } leaf--; cur++; }
            }
         }
         cout<<d+(leaf<=0)<<"\n";

         /* --------- */
            return;
    }

    signed main() {
       ios_base::sync_with_stdio(0);
       cin.tie(0);
       cout.tie(0);

         // cout<<fixed<<setprecision(10);

          int tututu;
          tututu=1;

         cin>>tututu; // если нет запросов, то закоментить

          for (int qwerty=0;qwerty<tututu;qwerty++) solve();

        return 0;
    }


#include <bits/stdc++.h>
#define int long long
#define YES cout<<"YES\n";return;
#define NO cout<<"NO\n";return;
#define write(a) cout<<a<<"\n";return;

using namespace std;
using vi=vector<int>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);
    long long powmod(long long a,long long b,long long mod) {
        if (b==0 || a==1)  {if (mod==1) return 0; else return 1; }

        if (b%2==0) { long long k=powmod(a,b/2,mod); return (k*k)%mod; }
        else {long long k=powmod(a,b/2,mod); return ( (k*k) %mod *a)% mod; }
    }
    long long gcd(long long a, long long b) {
        if (a==0) return b;
        if (b==0) return a;
        if (a>b) return gcd(a%b,b); else return gcd(b%a,a);
    }
      int prime(int p) { // 1 - простое
        for (int i=2;i*i<=p;i++) {
            if (p%i==0 && i<p) return i;
        }
        return 1;
    }

     int inv(int a, int mod) {
        return powmod(a,mod-2,mod);
    }

  int random_modul() {

    uniform_int_distribution <int> u1(1e9, 2e9);
    int pepega=u1(rnd);
    while (prime(pepega)!=1) pepega=u1(rnd);
    return pepega;
}

void ifmax(int &max, int kek) {
    if (kek>max) max=kek;
    return;
}
void ifmin(int &min, int kek) {
    if (kek<min) min=kek;
    return;
}

vector <vector<int>> digits;
int dist(vector<int> a, int digit) {
    int ans=0;
    for (int i=0;i<7;i++) { if (a[i]==1 && digits[digit][i]==0) ans=1000000; if (digits[digit][i]==1 && a[i]==0) ans++; }
    return ans;
}

    void solve () {

         /* --------- */

       int a;
       cin>>a;
       vi m(a);
       for (int i=0;i<a;i++) {
           cin>>m[i];
       }
       int d=1;
       int left=1;
       int cur=0;
       for (int i=1;i<a;i++) {
           if (i==1 || m[i]<m[i-1]) {
              if (left==0) {d++; left=cur; cur=1; } else left--;
           } else cur++;
       }
       cout<<d<<"\n";

           /* --------- */
            return;
    }

    signed main() {
       ios_base::sync_with_stdio(0);
       cin.tie(0);
       cout.tie(0);

         // cout<<fixed<<setprecision(10);

          int tututu;
          tututu=1;

        cin>>tututu; // если нет запросов, то закоментить

          for (int qwerty=0;qwerty<tututu;qwerty++) solve();

        return 0;
    }


#include <bits/stdc++.h>
#define int long long
#define YES cout<<"YES\n";return;
#define NO cout<<"NO\n";return;
#define write(a) cout<<a<<"\n";return;
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);
    long long powmod(long long a,long long b,long long mod) {
        if (b==0 || a==1)  {if (mod==1) return 0; else return 1; }

        if (b%2==0) { long long k=powmod(a,b/2,mod); return (k*k)%mod; }
        else {long long k=powmod(a,b/2,mod); return ( (k*k) %mod *a)% mod; }
    }
    long long gcd(long long a, long long b) {
        if (a==0) return b;
        if (b==0) return a;
        if (a>b) return gcd(a%b,b); else return gcd(b%a,a);
    }
      int prime(int p) { // 1 - простое
        for (int i=2;i*i<=p;i++) {
            if (p%i==0 && i<p) return i;
        }
        return 1;
    }

     int inv(int a, int mod) {
        return powmod(a,mod-2,mod);
    }

  int random_modul() {

    uniform_int_distribution <int> u1(1e9, 2e9);
    int pepega=u1(rnd);
    while (prime(pepega)!=1) pepega=u1(rnd);
    return pepega;
}

    void solve () {

         /* --------- */

         int a;
         cin>>a;
         int m[a];
         for (int i=0;i<a;i++) cin>>m[i];
         int left=1;
         int d=1;
         int leaf=0;
         int cur=0;
         int kek=0;
         for (int i=1;i<a;i++) {
            // cout<<leaf<<" "<<cur<<" "<<d<<"\n";
             if (i==1) { leaf=0; cur++;  }
            else {

                if (m[i]>m[i-1]) {cur++; }
                else {  if (!kek && leaf<=0) { d++; leaf=cur-1;  kek=1; }  cur++;

                }
                kek=0;
            }
         }
         cout<<d<<"\n";

         /* --------- */
            return;
    }

    signed main() {
       ios_base::sync_with_stdio(0);
       cin.tie(0);
       cout.tie(0);

         // cout<<fixed<<setprecision(10);

          int tututu;
          tututu=1;

         cin>>tututu; // если нет запросов, то закоментить

          for (int qwerty=0;qwerty<tututu;qwerty++) solve();

        return 0;
    }


#include <bits/stdc++.h>
#define int long long
#define YES cout<<"YES\n";return;
#define NO cout<<"NO\n";return;
#define write(a) cout<<a<<"\n";return;
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);
    long long powmod(long long a,long long b,long long mod) {
        if (b==0 || a==1)  {if (mod==1) return 0; else return 1; }

        if (b%2==0) { long long k=powmod(a,b/2,mod); return (k*k)%mod; }
        else {long long k=powmod(a,b/2,mod); return ( (k*k) %mod *a)% mod; }
    }
    long long gcd(long long a, long long b) {
        if (a==0) return b;
        if (b==0) return a;
        if (a>b) return gcd(a%b,b); else return gcd(b%a,a);
    }
      int prime(int p) { // 1 - простое
        for (int i=2;i*i<=p;i++) {
            if (p%i==0 && i<p) return i;
        }
        return 1;
    }

     int inv(int a, int mod) {
        return powmod(a,mod-2,mod);
    }

  int random_modul() {

    uniform_int_distribution <int> u1(1e9, 2e9);
    int pepega=u1(rnd);
    while (prime(pepega)!=1) pepega=u1(rnd);
    return pepega;
}

    void solve () {

         /* --------- */

         int a;
         cin>>a;
         int m[a];
         for (int i=0;i<a;i++) cin>>m[i];
         int left=1;
         int d=1;
         int leaf=0;
         int cur=0;
         int kek=0;
         for (int i=1;i<a;i++) {
            // cout<<leaf<<" "<<cur<<" "<<d<<"\n";
             if (i==1) { leaf=0; cur++;  }
            else {
                 int kek1=0;
                if (m[i]>m[i-1]) {cur++; }
                else { if (!kek) leaf--;
                if (leaf<0) { d++; leaf=cur-2;  kek1=1; }  cur++;

                }
                if (kek1==1) kek=1; else
                kek=0;
            }
         }
         cout<<d<<"\n";

         /* --------- */
            return;
    }

    signed main() {
       ios_base::sync_with_stdio(0);
       cin.tie(0);
       cout.tie(0);

         // cout<<fixed<<setprecision(10);

          int tututu;
          tututu=1;

         cin>>tututu; // если нет запросов, то закоментить

          for (int qwerty=0;qwerty<tututu;qwerty++) solve();

        return 0;
    }


#include <bits/stdc++.h>
#define int long long
#define YES cout<<"YES\n";return;
#define NO cout<<"NO\n";return;
#define write(a) cout<<a<<"\n";return;

using namespace std;
using vi=vector<int>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);
    long long powmod(long long a,long long b,long long mod) {
        if (b==0 || a==1)  {if (mod==1) return 0; else return 1; }

        if (b%2==0) { long long k=powmod(a,b/2,mod); return (k*k)%mod; }
        else {long long k=powmod(a,b/2,mod); return ( (k*k) %mod *a)% mod; }
    }
    long long gcd(long long a, long long b) {
        if (a==0) return b;
        if (b==0) return a;
        if (a>b) return gcd(a%b,b); else return gcd(b%a,a);
    }
      int prime(int p) { // 1 - простое
        for (int i=2;i*i<=p;i++) {
            if (p%i==0 && i<p) return i;
        }
        return 1;
    }

     int inv(int a, int mod) {
        return powmod(a,mod-2,mod);
    }

  int random_modul() {

    uniform_int_distribution <int> u1(1e9, 2e9);
    int pepega=u1(rnd);
    while (prime(pepega)!=1) pepega=u1(rnd);
    return pepega;
}

void ifmax(int &max, int kek) {
    if (kek>max) max=kek;
    return;
}
void ifmin(int &min, int kek) {
    if (kek<min) min=kek;
    return;
}

vector <vector<int>> digits;
int dist(vector<int> a, int digit) {
    int ans=0;
    for (int i=0;i<7;i++) { if (a[i]==1 && digits[digit][i]==0) ans=1000000; if (digits[digit][i]==1 && a[i]==0) ans++; }
    return ans;
}

    void solve () {

         /* --------- */

       int a;
       cin>>a;
       vi m(a);
       for (int i=0;i<a;i++) {
           cin>>m[i];
       }
       int d=1;
       int left=1;
       int cur=0;
       for (int i=1;i<a;i++) {
           if (m[i]<m[i-1]) {
               left--;
              if (left==0) {d++; left=cur;  }
           } else cur++;
       }
       cout<<d<<"\n";

           /* --------- */
            return;
    }

    signed main() {
       ios_base::sync_with_stdio(0);
       cin.tie(0);
       cout.tie(0);

         // cout<<fixed<<setprecision(10);

          int tututu;
          tututu=1;

        cin>>tututu; // если нет запросов, то закоментить

          for (int qwerty=0;qwerty<tututu;qwerty++) solve();

        return 0;
    }


//orz Gold_7
//orz SqwrIwy
//orz yzh1505
//orz yzh2019
//orz new
//orz hejinfan
//orz chenkuowen
//#pragma comment(linker,?STACK:1677721600?
//#pragma GCC optimize("O2")
//#pragma G++ optimize("O2")
//#pragma GCC optimize("O3")
//#pragma G++ optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef __int128 ll;
typedef unsigned int uint;
typedef unsigned long long ull;
//typedef double db;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
//typedef pair<ll,ll>P;
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define REP(i,n) for(int i=0;i<n;++i)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define fors(i) for(auto i:e[x]) if(i!=p)
#define ls p<<1
#define rs p<<1|1

#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define Flush FastIO::Fflush()

const int N=500010;
const int M=222222;
const int MOD=1e9+7;
const int intINF=int(1e9);
const ll llINF=ll(2e18);
const uint uintINF=~0U;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
const long double pi=acos(-1.0L);

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

/*
void pr128(__int128 x)
{
    if(x<0) putchar('-'),x=-x;
    if(x<10) return putchar('0'+x),void();
    pr128(x/10),putchar('0'+(x%10));
}*/

/*namespace FastIO
{
    const int SIZE = 1 << 16;
    char buf[SIZE], obuf[SIZE], str[60];
    int bi = SIZE, bn = SIZE, opt;
    double D[] = {0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001, 0.0000001, 0.00000001, 0.000000001, 0.0000000001};
    int read(char *s) {
        while (bn) {
            for (; bi < bn && buf[bi] <= ' '; bi++);
            if (bi < bn) break;
            bn = fread(buf, 1, SIZE, stdin);
            bi = 0;
        }
        int sn = 0;
        while (bn) {
            for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi];
            if (bi < bn) break;
            bn = fread(buf, 1, SIZE, stdin);
            bi = 0;
        }
        s[sn] = 0;
        return sn;
    }
    bool read(int& x) {
        int n = read(str), bf = 0;
        if (!n) return 0;
        int i = 0; if (str[i] == '-') bf = 1, i++; else if (str[i] == '+') i++;
        for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';
        if (bf) x = -x;
        return 1;
    }
    bool read(long long& x) {
        int n = read(str), bf;
        if (!n) return 0;
        int i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1;
        for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';
        if (bf < 0) x = -x;
        return 1;
    }
    void write(int x) {
        if (x == 0) obuf[opt++] = '0';
        else {
            if (x < 0) obuf[opt++] = '-', x = -x;
            int sn = 0;
            while (x) str[sn++] = x % 10 + '0', x /= 10;
            for (int i = sn - 1; i >= 0; i--) obuf[opt++] = str[i];
        }
        if (opt >= (SIZE >> 1)) {
            fwrite(obuf, 1, opt, stdout);
            opt = 0;
        }
    }
    void write(long long x) {
        if (x == 0) obuf[opt++] = '0';
        else {
            if (x < 0) obuf[opt++] = '-', x = -x;
            int sn = 0;
            while (x) str[sn++] = x % 10 + '0', x /= 10;
            for (int i = sn - 1; i >= 0; i--) obuf[opt++] = str[i];
        }
        if (opt >= (SIZE >> 1)) {
            fwrite(obuf, 1, opt, stdout);
            opt = 0;
        }
    }
    void write(unsigned long long x) {
        if (x == 0) obuf[opt++] = '0';
        else {
            int sn = 0;
            while (x) str[sn++] = x % 10 + '0', x /= 10;
            for (int i = sn - 1; i >= 0; i--) obuf[opt++] = str[i];
        }
        if (opt >= (SIZE >> 1)) {
            fwrite(obuf, 1, opt, stdout);
            opt = 0;
        }
    }
    void write(char x) {
        obuf[opt++] = x;
        if (opt >= (SIZE >> 1)) {
            fwrite(obuf, 1, opt, stdout);
            opt = 0;
        }
    }
    void Fflush() { if (opt) fwrite(obuf, 1, opt, stdout); opt = 0;}
};

//int x=read();   ->int x; FI(x);*/

/*auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);

ull SX=335634763,SY=873658265,SZ=192849106,SW=746126501;

inline ull xorshift128()
{
    ull t=SX^(SX<<11);
    SX=SY;
    SY=SZ;
    SZ=SW;
    return SW=SW^(SW>>19)^t^(t>>8);
}*/

int t[N<<2],a[N],dp[N],n;

void predo()
{
}

void init()
{
    n=read();
    rep(i,1,n) a[i]=read();
}

void pushup(int p)
{
    t[p]=max(t[ls],t[rs]);
}

void build(int l,int r,int p)
{
    t[p]=0;
    if(l==r) return;
    int mid=(l+r)>>1;
    build(l,mid,ls);
    build(mid+1,r,rs);
}

void update(int l,int r,int x,int y,int p)
{
    if(l==r)
    {
        t[p]=y;
        return;
    }
    int mid=(l+r)>>1;
    if(x<=mid) update(l,mid,x,y,ls);
     else update(mid+1,r,x,y,rs);
    pushup(p);
}

int query(int l,int r,int x,int y,int p)
{
    if(x>y) return 0;
    if(x<=l&&r<=y) return t[p];
    int mid=(l+r)>>1;
    int res=0;
    if(x<=mid) res=max(res,query(l,mid,x,y,ls));
    if(y>mid) res=max(res,query(mid+1,r,x,y,rs));
    return res;
}

void solve()
{
    int ans=0;
    build(1,n,1);
    rep(i,1,n)
    {
        dp[i]=query(1,n,a[i]+1,n,1)+1;
        ans=max(ans,dp[i]);
        update(1,n,a[i],dp[i],1);
    }
    printf("%d\n",ans);
}

int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    predo();
    int cas=read();
    //int cas=1;
    while(cas--)
    {
       init();
       solve();
    }
    return 0;
}


import java.util.Scanner;

	public class Solution {

		public static void main(String[] args) {

			Scanner scan = new Scanner(System.in);
			int t = scan.nextInt();

			while(t-->0) {
				int n =scan.nextInt();
				String str= scan.next();
				char c= (char)(pow(n) +1 +96);
				StringBuilder sb = new StringBuilder();
				sb.append(c);
				System.out.println(build(1,n,sb.toString(),str));
			}

			scan.close();
		}

		public static int build(int curr, int len, String s, String s2) {
			if(curr==len) {
				return compare(s,s2);
			}else {
				char c = (char)(pow(len/curr) + 96);
				StringBuilder sb = new StringBuilder();
				for(int i=0;i<curr;i++) {
					sb.append(c);
				}
				return Math.min(build(curr*2, len ,sb.toString()+s,s2),build(curr*2, len ,s+sb.toString(),s2));
			}
		}

		public static int pow(int num) {
			int n=0;
			while(num!=1) {
				num=num>>1;
				n++;
			}
			return n;
		}

		public static int compare(String s1, String s2) {
			int count=0;
			for(int i=0;i<s1.length();i++) {
				if(s1.charAt(i)!=s2.charAt(i)) count++;
			}
			return count;
		}
	}


import java.util.Scanner;

	public class Solution {

		public static void main(String[] args) {

			Scanner scan = new Scanner(System.in);
			int t = scan.nextInt();

			while(t-->0) {
				int n =scan.nextInt();
				String str= scan.next();
				System.out.println(count(str,'a'));

			}

			scan.close();
		}

		public static int count(String s, char c) {
			if(s.length()==1) {
				if(s.charAt(0)==c) return 0;
				else return 1;
			}
			int mid = s.length()/2;
			int lc = count(s.substring(0,mid),(char)(c+1));
			lc+=mid-countChar(s.substring(mid,s.length()), c);
			int rc = count(s.substring(mid,s.length()),(char)(c+1));
			rc+=mid-countChar(s.substring(0,mid), c);

			return Math.min(lc, rc);
		}

		public static int countChar(String s, char c) {
			int ans=0;
			for(int i=0;i<s.length();i++) {
				if(s.charAt(i)==c) ans++;
			}
			return ans;
		}

	}


import java.util.*;
import java.io.*;

public class Main {
    final static int maxn = 1000;

    static Scanner reader = new Scanner(System.in);
    static int n;
    static int val[][];
    static int lens[];
    static String s;

    static int cnt_dp(int let, int pos) {
        if(lens[let] == 1)
        return Math.min(val[let][pos] + (s.charAt(pos + 1) != ('a' + let + 1) ? 1 : 0),
            val[let][pos + 1] + (s.charAt(pos) != ('a' + let + 1) ? 1 : 0));
        return Math.min(val[let][pos] + cnt_dp(let + 1, pos + lens[let]),
                        val[let][pos + lens[let]] + cnt_dp(let + 1, pos));
    }

    static void solve() {
        n = reader.nextInt();
        s = reader.next();
        if(n == 1) {
            System.out.println(s == "a" ? 0 : 1);
            return;
        }
        val = new int[20][n];
        for(int i = 0; i < 20; i++) {
            for(int j = 0; j < n; j++) {
                val[i][j] = -1;
            }
        }
        int len = n;
        lens = new int[20];
        for(int i = 0; i < 20; i++) {
            len /= 2;
            if(len == 0) break;
            lens[i] = len;
            for(int pos = 0; pos < n; pos += len) {
                int cur = 0;
                for(int j = 0; j < len; j++) {
                    if(s.charAt(pos + j) != ('a' + i)) {
                        cur++;
                    }
                }
                val[i][pos] = cur;
            }
        }

        System.out.println(cnt_dp(0, 0));
    }

    public static void main(String[] args) {
        int q = reader.nextInt();
        for(int i = 0; i < q; i++) solve();
    }
}


import java.util.*;
import java.io.*;

public class Main {
    final static int maxn = 1000;

    static Scanner reader = new Scanner(System.in);
    static int n;
    static int val[][];
    static int lens[];
    static String s;

    static int cnt_dp(int let, int pos) {
        if(lens[let] == 1)
        return Math.min(val[let][pos] + (s.charAt(pos + 1) != ('a' + let + 1) ? 1 : 0),
            val[let][pos + 1] + (s.charAt(pos) != ('a' + let + 1) ? 1 : 0));
        return Math.min(val[let][pos] + cnt_dp(let + 1, pos + lens[let]),
                        val[let][pos + lens[let]] + cnt_dp(let + 1, pos));
    }

    static void solve() {
        n = reader.nextInt();
        s = reader.next();
        if(n == 1) {
            System.out.println(s.equals("a") ? 0 : 1);
            return;
        }
        val = new int[20][n];
        for(int i = 0; i < 20; i++) {
            for(int j = 0; j < n; j++) {
                val[i][j] = -1;
            }
        }
        int len = n;
        lens = new int[20];
        for(int i = 0; i < 20; i++) {
            len /= 2;
            if(len == 0) break;
            lens[i] = len;
            for(int pos = 0; pos < n; pos += len) {
                int cur = 0;
                for(int j = 0; j < len; j++) {
                    if(s.charAt(pos + j) != ('a' + i)) {
                        cur++;
                    }
                }
                val[i][pos] = cur;
            }
        }

        System.out.println(cnt_dp(0, 0));
    }

    public static void main(String[] args) {
        int q = reader.nextInt();
        for(int i = 0; i < q; i++) solve();
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * @author Tran Anh Tai
 * @template for CP codes
 */
public class ProbD {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
    // main solver
    static class Task {
        public void solve(InputReader in, PrintWriter out) {
            int t = in.nextInt();
            for(int i = 0; i < t; i++){
                int n = in.nextInt();
                String s = in.nextToken();
                int[][] cnt = new int[n + 1][26];
                for(int j = 1; j <= n; j++){
                    for (int c = 0; c < 26; c++){
                        cnt[j][c] = cnt[j - 1][c];
                    }
                    cnt[j][s.charAt(j - 1) - 'a']++;
                }
                int dp[][] = new int[n + 1][18];
                int k = (int)(Math.log(n) / Math.log(2));
                for (int j = 1; j <= n; j++){
                    dp[j][0] = (s.charAt(j - 1) - 'a' == k) ? 0 : 1;
                }
                for (int c = 1; c <= k; c++){
                    for (int j = 1; j <= n; j++){
                        if (j + (1 << c) - 1  <= n){
                            dp[j][c] = Math.min(dp[j][c - 1] + cnt[j + (1 << c) - 1][c] - cnt[j + (1 << (c - 1)) - 1][c],
                                                dp[j + (1 << (c - 1))][c - 1] + cnt[j + (1 << (c - 1))][c] - cnt[j - 1][c]);
                        }
                    }
                }
                out.println(dp[n][k]);
            }
        }
    }
    public static class Segment implements Comparable<Segment>{
        public int l, r;
        public Segment(int l, int r){
            this.l = l;
            this.r = r;
        }

        @Override
        public int compareTo(Segment o) {
            if (o.r != this.r){
                return Integer.compare(this.r, o.r);
            }
            return Integer.compare(this.l, o.l);
        }
        public static boolean isIntersect(Segment s1, Segment s2){
            if (s1.l > s2.r || s2.l > s1.r){
                return false;
            }
            return true;
        }
    }
    // fast input reader class;
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (line == null) {
                    return null;
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        public long nextLong(){
            return Long.parseLong(nextToken());
        }
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * @author Tran Anh Tai
 * @template for CP codes
 */
public class ProbD {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
    // main solver
    static class Task {
        public void solve(InputReader in, PrintWriter out) {
            int t = in.nextInt();
            for(int i = 0; i < t; i++){
                int n = in.nextInt();
                String s = in.nextToken();
                int[][] cnt = new int[n + 1][26];
                for(int j = 1; j <= n; j++){
                    for (int c = 0; c < 26; c++){
                        cnt[j][c] = cnt[j - 1][c];
                    }
                    cnt[j][s.charAt(j - 1) - 'a']++;
                }
                int dp[][] = new int[n + 1][18];
                int k = (int)(Math.log(n) / Math.log(2));
                for (int j = 1; j <= n; j++){
                    dp[j][0] = (s.charAt(j - 1) - 'a' == k) ? 0 : 1;
                }
                assert (n == (1 << k));
                for (int c = 1; c <= k; c++){
                    for (int j = 1; j <= n; j++){
                        if (j + (1 << c) - 1  <= n){
                            dp[j][c] = Math.min(dp[j][c - 1] + (1 << (c - 1)) - (cnt[j + (1 << c) - 1][k - c] - cnt[j + (1 << (c - 1)) - 1][k - c]),
                                                dp[j + (1 << (c - 1))][c - 1] + (1 << (c - 1)) - (cnt[j + (1 << (c - 1)) - 1][k - c] - cnt[j - 1][k - c]));
                        }
                    }
                }
                out.println(dp[1][k]);
            }
        }
    }
    public static class Segment implements Comparable<Segment>{
        public int l, r;
        public Segment(int l, int r){
            this.l = l;
            this.r = r;
        }

        @Override
        public int compareTo(Segment o) {
            if (o.r != this.r){
                return Integer.compare(this.r, o.r);
            }
            return Integer.compare(this.l, o.l);
        }
        public static boolean isIntersect(Segment s1, Segment s2){
            if (s1.l > s2.r || s2.l > s1.r){
                return false;
            }
            return true;
        }
    }
    // fast input reader class;
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (line == null) {
                    return null;
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        public long nextLong(){
            return Long.parseLong(nextToken());
        }
    }
}


import java.io.*;
import java.math.*;
import java.util.*;

public class Main implements Runnable {

	class Pair implements Comparable<Pair>{
		public int node;
		public int count;
		Pair(int nd, int c){
			node=nd; count=c;
		}
		public int compareTo(Pair that) {
	        return that.count -  this.count;
	    }
	}

	int getMin(int a[], int start, int end, int val){
		if(start==end){
			if(a[start]==val)
				return 0;
			else
				return 1;
		}
		int mid= (start+end)/2;

		int count1=0;
		for(int i=start;i<=mid;i++){
			if(a[i]!=val)
				count1++;
		}
		int m1= count1+getMin(a,mid+1,end,val+1);

		int count2=0;
		for(int i=mid+1;i<=end;i++){
			if(a[i]!=val)
				count2++;
		}
		int m2= count2+getMin(a,start,mid,val+1);

		return Math.min(m1, m2);
	}
	public void solve() throws Exception {

		int t=iread();
		for(int cases=1;cases<=t;cases++){
			int n= iread();
			String s= readword();
			int a[]= new int[n+1];
			for(int i=0;i<n;i++)
				a[i]= (int)s.charAt(i);

			int result= getMin(a,0,n-1,(int)'a');
			System.out.println(result);
		}
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));
			// in = new BufferedReader(new FileReader(filename+".in"));
			// out = new BufferedWriter(new FileWriter(filename+".out"));
			solve();
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public int iread() throws Exception {
		return Integer.parseInt(readword());
	}

	public double dread() throws Exception {
		return Double.parseDouble(readword());
	}

	public long lread() throws Exception {
		return Long.parseLong(readword());
	}

	BufferedReader in;

	BufferedWriter out;

	public String readword() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) {

		try {
			Locale.setDefault(Locale.US);
		} catch (Exception e) {

		}
		// new Thread(new Main()).start();
		new Thread(null, new Main(), "1", 1 << 25).start();
	}
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Q417July {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t!=0){
            t--;
            int n = sc.nextInt();
            String s = sc.next();
            List<String> strings = fillStrings(n,'a');
           // System.out.println(strings);
           System.out.println(findMin(s,strings));
        }
    }

    private static int findMin(String s, List<String> strings){
        int min = Integer.MAX_VALUE;
        for (String string : strings) {
            int count = findCount(s, string);
            if (count < min) {
                min = count;
            }
        }
        return min;
    }

    private static int findCount(String s, String match){
        int count=0;
        for(int i =0;i<s.length();i++){
            if(s.charAt(i)!= match.charAt(i)){
                count++;
            }
        }
        return count;
    }

    private static List<String> fillStrings(int length, char initial){
        if(length == 1){
            return new ArrayList<>(
                    Collections.singletonList((Character.toString(initial))));
        }

        List<String> s1 = fillStrings(length/2, (char)(initial+1));
        List<String> s2 = fillStrings(length/2,(char)(initial+1));
       return appendBeforeAfter(s1,s2,initial, length/2);
    }

    private static  List<String> appendBeforeAfter(List<String> appendBeforeList, List<String> appendAfterString, char appendWith, int length){
        String repeatedInitials =  repeatedInitials(appendWith,length);
        List<String> newBefore = new ArrayList<>();
        List<String> newAfter = new ArrayList<>();
        for (String s : appendBeforeList) {
            s= repeatedInitials+s;
            newBefore.add(s);
        }

        for (String s : appendAfterString) {
            s+=repeatedInitials;
            newAfter.add(s);
        }

        newBefore.addAll(newAfter);

        return newBefore;
    }

    private static String repeatedInitials(char initials, int length){
        String s = "";
        for(int i =0;i<length;i++)
        {
            s+=(initials);
        }
        return s;
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Q417July {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t!=0){
            t--;
            int n = sc.nextInt();
            String s = sc.next();
            List<StringBuilder> strings = fillStrings(n,'a');
            System.out.println(findMin(s,strings));
        }
    }

    private static int findMin(String s, List<StringBuilder> strings){
        int min = Integer.MAX_VALUE;
        for (StringBuilder string : strings) {
            int count = findCount(s, string.toString());
            if (count < min) {
                min = count;
            }
        }
        return min;
    }

    private static int findCount(String s, String match){
        int count=0;
        for(int i =0;i<s.length();i++){
            if(s.charAt(i)!= match.charAt(i)){
                count++;
            }
        }
        return count;
    }

    private static List<StringBuilder> fillStrings(int length, char initial){
        if(length == 1){
            return new ArrayList<>(
                    Collections.singletonList(new StringBuilder(Character.toString(initial))));
        }

        List<StringBuilder> s1 = fillStrings(length/2, (char)(initial+1));
        List<StringBuilder> s2 = new ArrayList<>(s1);
        appendBeforeAfter(s1,s2,initial, length/2);
        s1.addAll(s2);
        return s1;
    }

    private static  void appendBeforeAfter(List<StringBuilder> appendBeforeList, List<StringBuilder> appendAfterString, char appendWith, int length){
        String repeatedInitials =  repeatedInitials(appendWith,length);
        for (StringBuilder s : appendBeforeList) {
            s.reverse().append(repeatedInitials).reverse();
        }

        for (StringBuilder s : appendAfterString) {
            s.append(repeatedInitials);
        }
    }

    private static String repeatedInitials(char initials, int length){
        StringBuilder s = new StringBuilder();
        for(int i =0;i<length;i++)
        {
            s.append(initials);
        }
        return s.toString();
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Q417July {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t!=0){
            t--;
            int n = sc.nextInt();
            String s = sc.next();
            List<StringBuilder> strings = fillStrings(4,'a');
            System.out.println(strings);
            System.out.println(findMin(s,strings));
        }
    }

    private static int findMin(String s, List<StringBuilder> strings){
        int min = Integer.MAX_VALUE;
        for (StringBuilder string : strings) {
            int count = findCount(s, string.toString());
            if (count < min) {
                min = count;
            }
        }
        return min;
    }

    private static int findCount(String s, String match){
        int count=0;
        for(int i =0;i<s.length();i++){
            if(s.charAt(i)!= match.charAt(i)){
                count++;
            }
        }
        return count;
    }

    private static List<StringBuilder> fillStrings(int length, char initial){
        if(length == 1){
            return new ArrayList<>(
                    Collections.singletonList(new StringBuilder(Character.toString(initial))));
        }

        List<StringBuilder> s1 = fillStrings(length/2, (char)(initial+1));
        List<StringBuilder> s2 = new ArrayList<>();
        for (StringBuilder stringBuilder : s1) {
            s2.add(new StringBuilder(stringBuilder.toString()));
        }
        appendBeforeAfter(s1,s2,initial, length/2);
        s1.addAll(s2);
        return s1;
    }

    private static  void appendBeforeAfter(List<StringBuilder> appendBeforeList, List<StringBuilder> appendAfterString, char appendWith, int length){
        String repeatedInitials =  repeatedInitials(appendWith,length);
        for (StringBuilder s : appendBeforeList) {
            s.reverse().append(repeatedInitials).reverse();
        }

        for (StringBuilder s : appendAfterString) {
            s.append(repeatedInitials);
        }
    }

    private static String repeatedInitials(char initials, int length){
        StringBuilder s = new StringBuilder();
        for(int i =0;i<length;i++)
        {
            s.append(initials);
        }
        return s.toString();
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Q417July {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t!=0){
            t--;
            int n = sc.nextInt();
            String s = sc.next();
            List<StringBuilder> strings = fillStrings(n,'a');
            System.out.println(strings);
            System.out.println(findMin(s,strings));
        }
    }

    private static int findMin(String s, List<StringBuilder> strings){
        int min = Integer.MAX_VALUE;
        for (StringBuilder string : strings) {
            int count = findCount(s, string.toString());
            if (count < min) {
                min = count;
            }
        }
        return min;
    }

    private static int findCount(String s, String match){
        int count=0;
        for(int i =0;i<s.length();i++){
            if(s.charAt(i)!= match.charAt(i)){
                count++;
            }
        }
        return count;
    }

    private static List<StringBuilder> fillStrings(int length, char initial){
        if(length == 1){
            return new ArrayList<>(
                    Collections.singletonList(new StringBuilder(Character.toString(initial))));
        }

        List<StringBuilder> s1 = fillStrings(length/2, (char)(initial+1));
        List<StringBuilder> s2 = new ArrayList<>();
        for (StringBuilder stringBuilder : s1) {
            s2.add(new StringBuilder(stringBuilder.toString()));
        }
        appendBeforeAfter(s1,s2,initial, length/2);
        s1.addAll(s2);
        return s1;
    }

    private static  void appendBeforeAfter(List<StringBuilder> appendBeforeList, List<StringBuilder> appendAfterString, char appendWith, int length){
        String repeatedInitials =  repeatedInitials(appendWith,length);
        for (StringBuilder s : appendBeforeList) {
            s.reverse().append(repeatedInitials).reverse();
        }

        for (StringBuilder s : appendAfterString) {
            s.append(repeatedInitials);
        }
    }

    private static String repeatedInitials(char initials, int length){
        StringBuilder s = new StringBuilder();
        for(int i =0;i<length;i++)
        {
            s.append(initials);
        }
        return s.toString();
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Q417July {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t!=0){
            t--;
            int n = sc.nextInt();
            String s = sc.next();
           // System.out.println(strings);
           System.out.println(findMin(s,0,n-1,'a'));
        }
    }

    private static int findMin(String s, int l, int r, char ch){
       if(l>=r){
           if(s.charAt(l)!=ch){
               return 1;
           }
           return 0;
       }
       int mid = l+r/2;
       int left =0;
       int right =0;
       for(int i=l;i<=mid;i++){
           if(s.charAt(i)!=ch){
               left++;
           }
       }
        for(int i=mid+1;i<=r;i++){
            if(s.charAt(i)!=ch){
                right++;
            }
        }
        ++ch;

        return Math.min(left+ findMin(s,mid+1,r,ch), right+ findMin(s,l,mid-1,ch));
    }

    private static int findCount(String s, String match){
        int count=0;
        for(int i =0;i<s.length();i++){
            if(s.charAt(i)!= match.charAt(i)){
                count++;
            }
        }
        return count;
    }

    private static List<String> fillStrings(int length, char initial){
        if(length == 1){
            return new ArrayList<>(
                    Collections.singletonList((Character.toString(initial))));
        }

        List<String> s1 = fillStrings(length/2, (char)(initial+1));
        List<String> s2 = fillStrings(length/2,(char)(initial+1));
       return appendBeforeAfter(s1,s2,initial, length/2);
    }

    private static  List<String> appendBeforeAfter(List<String> appendBeforeList, List<String> appendAfterString, char appendWith, int length){
        String repeatedInitials =  repeatedInitials(appendWith,length);
        List<String> newBefore = new ArrayList<>();
        List<String> newAfter = new ArrayList<>();
        for (String s : appendBeforeList) {
            s= repeatedInitials+s;
            newBefore.add(s);
        }

        for (String s : appendAfterString) {
            s+=repeatedInitials;
            newAfter.add(s);
        }

        newBefore.addAll(newAfter);

        return newBefore;
    }

    private static String repeatedInitials(char initials, int length){
        String s = "";
        for(int i =0;i<length;i++)
        {
            s+=(initials);
        }
        return s;
    }
}


import java.util.*;

public class Q417July {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t!=0){
            t--;
            int n = sc.nextInt();
            String s = sc.next();
            List<StringBuilder> strings = fillStrings(n,'a');
            System.out.println(findMin(s,strings));
        }
    }

    private static int findMin(String s, List<StringBuilder> strings){
        int min = Integer.MAX_VALUE;
        for (StringBuilder string : strings) {
            int count = findCount(s, string.toString());
            if (count < min) {
                min = count;
            }
        }
        return min;
    }

    private static int findCount(String s, String match){
        int count=0;
        for(int i =0;i<s.length();i++){
            char ch = s.charAt(i);
            char ch1 = match.charAt(i);
            if(ch!=ch1){
                count++;
            }
        }
        return count;
    }

    private static List<StringBuilder> fillStrings(int length, char initial){
        if(length == 1){
            return new ArrayList<>(
                    Collections.singletonList(new StringBuilder(Character.toString(initial))));
        }

        List<StringBuilder> s1 = fillStrings(length/2, (char)(initial+1));
        List<StringBuilder> s2 = fillStrings(length/2, (char)(initial+1));
        appendBeforeAfter(s1,s2,initial, length/2);
        s1.addAll(s2);
        return s1;
    }

    private static  void appendBeforeAfter(List<StringBuilder> appendBeforeList, List<StringBuilder> appendAfterString, char appendWith, int length){
        String repeatedInitials =  repeatedInitials(appendWith,length);
        for (StringBuilder s : appendBeforeList) {
            s.reverse().append(repeatedInitials).reverse();
        }

        for (StringBuilder s : appendAfterString) {
            s.append(repeatedInitials);
        }
    }

    private static String repeatedInitials(char initials, int length){
        StringBuilder s = new StringBuilder();
        for(int i =0;i<length;i++)
        {
            s.append(initials);
        }
        return s.toString();
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Q417July {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t!=0){
            t--;
            int n = sc.nextInt();
            String s = sc.next();
           // System.out.println(strings);
           System.out.println(findMin(s,0,n-1,'a'));
        }
    }

    private static int findMin(String s, int l, int r, char ch){
       if(l>=r){
           if(s.charAt(l)!=ch){
               return 1;
           }
           return 0;
       }
       int mid = (l+r)/2;
       int left =0;
       int right =0;
       for(int i=l;i<=mid;i++){
           if(s.charAt(i)!=ch){
               left++;
           }
       }
        for(int i=mid+1;i<=r;i++){
            if(s.charAt(i)!=ch){
                right++;
            }
        }
         ch = (char)(ch+1);

        return Math.min(left+ findMin(s,mid+1,r,ch), right+ findMin(s,l,mid,ch));
    }

    private static int findCount(String s, String match){
        int count=0;
        for(int i =0;i<s.length();i++){
            if(s.charAt(i)!= match.charAt(i)){
                count++;
            }
        }
        return count;
    }

    private static List<String> fillStrings(int length, char initial){
        if(length == 1){
            return new ArrayList<>(
                    Collections.singletonList((Character.toString(initial))));
        }

        List<String> s1 = fillStrings(length/2, (char)(initial+1));
        List<String> s2 = fillStrings(length/2,(char)(initial+1));
       return appendBeforeAfter(s1,s2,initial, length/2);
    }

    private static  List<String> appendBeforeAfter(List<String> appendBeforeList, List<String> appendAfterString, char appendWith, int length){
        String repeatedInitials =  repeatedInitials(appendWith,length);
        List<String> newBefore = new ArrayList<>();
        List<String> newAfter = new ArrayList<>();
        for (String s : appendBeforeList) {
            s= repeatedInitials+s;
            newBefore.add(s);
        }

        for (String s : appendAfterString) {
            s+=repeatedInitials;
            newAfter.add(s);
        }

        newBefore.addAll(newAfter);

        return newBefore;
    }

    private static String repeatedInitials(char initials, int length){
        String s = "";
        for(int i =0;i<length;i++)
        {
            s+=(initials);
        }
        return s;
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Q417July {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t!=0){
            t--;
            int n = sc.nextInt();
            String s = sc.next();
            List<String> strings = fillStrings(n,'a');
           // System.out.println(strings);
           System.out.println(findMin(s,strings));
        }
    }

    private static int findMin(String s, List<String> strings){
        int min = Integer.MAX_VALUE;
        for (String string : strings) {
            int count = findCount(s, string);
            if (count < min) {
                min = count;
            }
        }
        return min;
    }

    private static int findCount(String s, String match){
        int count=0;
        for(int i =0;i<s.length();i++){
            if(s.charAt(i)!= match.charAt(i)){
                count++;
            }
        }
        return count;
    }

    private static List<String> fillStrings(int length, char initial){
        if(length == 1){
            return new ArrayList<>(
                    Collections.singletonList((Character.toString(initial))));
        }

        List<String> s1 = fillStrings(length/2, (char)(initial+1));
        List<String> s2 = fillStrings(length/2,(char)(initial+1));
       return appendBeforeAfter(s1,s2,initial, length/2);
    }

    private static  List<String> appendBeforeAfter(List<String> appendBeforeList, List<String> appendAfterString, char appendWith, int length){
        String repeatedInitials =  repeatedInitials(appendWith,length);
        List<String> newBefore = new ArrayList<>();
        List<String> newAfter = new ArrayList<>();
        for (String s : appendBeforeList) {
            s= repeatedInitials+s;
            newBefore.add(s);
        }

        for (String s : appendAfterString) {
            s+=repeatedInitials;
            newAfter.add(s);
        }

        newBefore.addAll(newAfter);

        return newBefore;
    }

    private static String repeatedInitials(char initials, int length){
        StringBuilder s = new StringBuilder();
        for(int i =0;i<length;i++)
        {
            s.append(initials);
        }
        return s.toString();
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Q417July {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t!=0){
            t--;
            int n = sc.nextInt();
            String s = sc.next();
            List<StringBuilder> strings = fillStrings(n,'a');
            System.out.println(findMin(s,strings));
        }
    }

    private static int findMin(String s, List<StringBuilder> strings){
        int min = Integer.MAX_VALUE;
        for (StringBuilder string : strings) {
            int count = findCount(s, string.toString());
            if (count < min) {
                min = count;
            }
        }
        return min;
    }

    private static int findCount(String s, String match){
        int count=0;
        for(int i =0;i<s.length();i++){
            if(s.charAt(i)!= match.charAt(i)){
                count++;
            }
        }
        return count;
    }

    private static List<StringBuilder> fillStrings(int length, char initial){
        if(length == 1){
            return new ArrayList<>(
                    Collections.singletonList(new StringBuilder(Character.toString(initial))));
        }

        List<StringBuilder> s1 = fillStrings(length/2, (char)(initial+1));
        List<StringBuilder> s2 = new ArrayList<>();
        for (StringBuilder stringBuilder : s1) {
            s2.add(new StringBuilder(stringBuilder.toString()));
        }
        appendBeforeAfter(s1,s2,initial, length/2);
        s1.addAll(s2);
        return s1;
    }

    private static  void appendBeforeAfter(List<StringBuilder> appendBeforeList, List<StringBuilder> appendAfterString, char appendWith, int length){
        String repeatedInitials =  repeatedInitials(appendWith,length);
        for (StringBuilder s : appendBeforeList) {
            s.reverse().append(repeatedInitials).reverse();
        }

        for (StringBuilder s : appendAfterString) {
            s.append(repeatedInitials);
        }
    }

    private static String repeatedInitials(char initials, int length){
        StringBuilder s = new StringBuilder();
        for(int i =0;i<length;i++)
        {
            s.append(initials);
        }
        return s.toString();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class scratch_25 {
    static class Reader {
        static BufferedReader reader;
        static StringTokenizer tokenizer;

        /**
         * call this method to initialize reader for InputStream
         */
        static void init(InputStream input) {
            reader = new BufferedReader(
                    new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }

        /**
         * get next word
         */
        static String next() throws IOException {
            while (!tokenizer.hasMoreTokens()) {
                //TODO add check for eof if necessary
                tokenizer = new StringTokenizer(
                        reader.readLine());
            }
            return tokenizer.nextToken();
        }

        static int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        static double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        static long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

    public static class Graph{
        public static class Vertex{
            HashMap<Integer,Integer> nb= new HashMap<>();     // for neighbours of each vertex
        }

        public static HashMap<Integer,Vertex> vt;   // for vertices(all)

        public Graph(){
            vt= new HashMap<>();
        }

        public static int numVer(){
            return vt.size();
        }

        public static boolean contVer(int ver){
            return vt.containsKey(ver);
        }

        public static void addVer(int ver){
            Vertex v= new Vertex();
            vt.put(ver,v);
        }

        public static int numEdg(){
            int count=0;
            ArrayList<Integer> vrtc= new ArrayList<>(vt.keySet());
            for (int i = 0; i <vrtc.size() ; i++) {
                count+=(vt.get(vrtc.get(i))).nb.size();
            }
            return count/2;
        }

        public static boolean contEdg(int ver1, int ver2){
            if(vt.get(ver1)==null || vt.get(ver2)==null){
                return false;
            }

            Vertex v= vt.get(ver1);
            if(v.nb.containsKey(ver2)){
                return true;
            }
            return false;
        }

        public static void addEdge(int ver1, int ver2, int weight){
            if(!vt.containsKey(ver1) || !vt.containsKey(ver2)){
                return;
            }
            Vertex v1= vt.get(ver1);
            Vertex v2= vt.get(ver2);
            v1.nb.put(ver2,weight);                                 // if previously there is an edge, then this replaces that edge
            v2.nb.put(ver1,weight);
        }

        public static void delEdge(int ver1, int ver2){

            if(!vt.containsKey(ver1) || !vt.containsKey(ver2)){
                return;
            }

            vt.get(ver1).nb.remove(ver2);
            vt.get(ver2).nb.remove(ver1);

        }

        public static void delVer(int ver){
            if(!vt.containsKey(ver)){
                return;
            }
            Vertex v1= vt.get(ver);
            ArrayList<Integer> arr= new ArrayList<>(v1.nb.keySet());
            for (int i = 0; i <arr.size() ; i++) {
                int s= arr.get(i);
                vt.get(s).nb.remove(ver);
            }
            vt.remove(ver);
        }

        public class Pair{
            int vname;
            ArrayList<Integer> psf= new ArrayList<>();       // path so far
            int dis;
            int col;
        }

        public HashMap<Integer,Integer> bfs(int src){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> queue= new LinkedList<>();      // for bfs queue

            Pair strtp= new Pair();

            strtp.vname= src;

            ArrayList<Integer> ar= new ArrayList<>();
            ar.add(src);

            strtp.psf= ar;
            strtp.dis=0;

            queue.addLast(strtp);

            while(!queue.isEmpty()){

                Pair rp =  queue.removeFirst();

                if(prcd.containsKey(rp.vname)){
                    continue;
                }
                prcd.put(rp.vname,true);
                ans.put(rp.vname,rp.dis);

//                if(contEdg(rp.vname,dst)){
//                    return true;
//                }

                Vertex a= vt.get(rp.vname);
                ArrayList<Integer> arr= new ArrayList<>(a.nb.keySet());
                for (int i = 0; i <arr.size() ; i++) {
                    int s= arr.get(i);
                    if(!prcd.containsKey(s)){
                        Pair np = new Pair();
                        np.vname= s;
                        np.dis+=rp.dis+a.nb.get(s);
                        np.psf.addAll(rp.psf);
                        np.psf.add(s);
//                        np.psf.add(s);
//                         np.psf= rp.psf+" "+s;
                        queue.addLast(np);
                    }

                }
            }
            return ans;

            //   return false;
        }

        public HashMap<Integer,Integer> dfs(int src){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> stack= new LinkedList<>();      // for bfs queue

            Pair strtp= new Pair();

            strtp.vname= src;

            ArrayList<Integer> ar= new ArrayList<>();
            ar.add(src);

            strtp.psf= ar;
            strtp.dis=0;

            stack.addFirst(strtp);

            while(!stack.isEmpty()){

                Pair rp =  stack.removeFirst();

                if(prcd.containsKey(rp.vname)){
                    continue;
                }
                prcd.put(rp.vname,true);
                ans.put(rp.vname,rp.dis);

//                if(contEdg(rp.vname,dst)){
//                    return true;
//                }

                Vertex a= vt.get(rp.vname);
                ArrayList<Integer> arr= new ArrayList<>(a.nb.keySet());
                for (int i = 0; i <arr.size() ; i++) {
                    int s= arr.get(i);
                    if(!prcd.containsKey(s)){
                        Pair np = new Pair();
                        np.vname= s;
                        np.dis+=rp.dis+a.nb.get(s);
                        np.psf.addAll(rp.psf);
                        np.psf.add(s);
//                        np.psf.add(s);
//                         np.psf= rp.psf+" "+s;
                        stack.addFirst(np);
                    }

                }
            }
            return ans;

            //   return false;
        }

        public boolean isCycle(){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            //   HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> queue= new LinkedList<>();      // for bfs queue

            ArrayList<Integer> keys = new ArrayList<>(vt.keySet());
            for (int i = 0; i <keys.size(); i++) {
                int cur= keys.get(i);
                if(prcd.containsKey(cur)){
                    continue;
                }

                Pair sp = new Pair();
                sp.vname= cur;
                ArrayList<Integer> as= new ArrayList<>();
                as.add(cur);
                sp.psf= as;

                queue.addLast(sp);

                while(!queue.isEmpty()){

                    Pair rp= queue.removeFirst();
                    if(prcd.containsKey(rp.vname)){
                        return true;
                    }

                    prcd.put(rp.vname,true);

                    Vertex v1= vt.get(rp.vname);
                    ArrayList<Integer> nbrs= new ArrayList<>(v1.nb.keySet());
                    for (int j = 0; j <nbrs.size() ; j++) {
                        int u= nbrs.get(j);
                        Pair np= new Pair();
                        np.vname= u;
                        queue.addLast(np);
                    }
                }

            }
            return false;
        }

        public  ArrayList<ArrayList<Integer>> genConnctdComp(){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            ArrayList<ArrayList<Integer>> ans= new ArrayList<>();

            //   HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> queue= new LinkedList<>();      // for bfs queue

            //  int con=-1;

            ArrayList<Integer> keys = new ArrayList<>(vt.keySet());
            for (int i = 0; i <keys.size(); i++) {
                int cur= keys.get(i);
                if(prcd.containsKey(cur)){
                    //return true;
                    continue;
                }
                ArrayList<Integer> fu= new ArrayList<>();
                fu.add(cur);

                Pair sp = new Pair();
                sp.vname= cur;
                ArrayList<Integer> as= new ArrayList<>();
                as.add(cur);
                sp.psf= as;

                queue.addLast(sp);

                while(!queue.isEmpty()){

                    Pair rp= queue.removeFirst();
                    if(prcd.containsKey(rp.vname)){
                        //return true;
                        continue;
                    }

                    prcd.put(rp.vname,true);
                    fu.add(cur);

                    Vertex v1= vt.get(rp.vname);
                    ArrayList<Integer> nbrs= new ArrayList<>();
                    for (int j = 0; j <nbrs.size() ; j++) {
                        int u= nbrs.get(j);
                        Pair np= new Pair();
                        np.vname= u;
                        queue.addLast(np);
                    }
                }
                ans.add(fu);

            }
            //return false;
            return ans;

        }

        public boolean isBip(int src){                       // only for connected graph

            HashMap<Integer,Integer> clr= new HashMap<>();
            // colors are 1 and -1

            LinkedList<Integer>q = new LinkedList<Integer>();
            clr.put(src,1);
            q.add(src);

            while(!q.isEmpty()){

                int u = q.getFirst();
                q.pop();

                ArrayList<Integer> arr= new ArrayList<>(vt.keySet());

                for (int i = 0; i <arr.size() ; ++i) {

                    int x= arr.get(i);

                    if(vt.get(u).nb.containsKey(x) && !clr.containsKey(x)){

                        if(clr.get(u)==1){
                            clr.put(x,-1);
                        }
                        else{
                            clr.put(x,1);
                        }
                        q.push(x);
                    }

                    else if(vt.get(u).nb.containsKey(x) && (clr.get(x)==clr.get(u))){
                        return false;
                    }

                }
            }
            return true;
        }

        public static void printGr() {
            ArrayList<Integer> arr= new ArrayList<>(vt.keySet());
            for (int i = 0; i <arr.size() ; i++) {
                int ver= arr.get(i);
                Vertex v1= vt.get(ver);
                ArrayList<Integer> arr1= new ArrayList<>(v1.nb.keySet());
                for (int j = 0; j <arr1.size() ; j++) {
                    System.out.println(ver+"-"+arr1.get(j)+":"+v1.nb.get(arr1.get(j)));
                }

            }
        }
    }

    public static void main(String[] args)  throws IOException {
        Reader.init(System.in);
        int t = Reader.nextInt();
        for (int j = 0; j < t; j++) {
            int n= Reader.nextInt();
            char arr[]= Reader.next().toCharArray();
            int x= good(arr,n,97);
            System.out.println(x);

        }

    }

    public static int good(char arr[],int n, int ac){
        if(n==1){
            if((int)arr[0]==ac){
                return 0;
            }
            else{
                return 1;
            }
        }
        int mid= arr.length/2;
        int count=0;
        int count1=0;
        for (int i = 0; i <mid ; i++) {
            char c= arr[i];
            int num= (int)c;
            if(num!=ac){
                count++;
            }
        }
        for (int i = mid; i <arr.length ; i++) {
            char c= arr[i];
            int num= (int)c;
            if(num!=ac){
                count1++;
            }
        }
        if(count>count1){
            return count1+good(Arrays.copyOfRange(arr,0,mid),n/2,ac+1);
        }
        else if(count<count1){
            return count+good(Arrays.copyOfRange(arr,mid,n),n/2,ac+1);
        }
        else{
            return Math.min( count1+good(Arrays.copyOfRange(arr,0,mid),n/2,ac+1),count+good(Arrays.copyOfRange(arr,mid,n),n/2,ac+1));
        }

    }

    public static ArrayList<Integer> Sieve(int n) {
        boolean arr[]= new boolean [n+1];
        Arrays.fill(arr,true);
        arr[0]=false;
        arr[1]=false;
        for (int i = 2; i*i <=n ; i++) {
            if(arr[i]==true){
                for (int j = 2; j <=n/i ; j++) {
                    int u= i*j;
                    arr[u]=false;
                }}
        }
        ArrayList<Integer> ans= new ArrayList<>();
        for (int i = 0; i <n+1 ; i++) {
            if(arr[i]){
                ans.add(i);
            }
        }
        return ans;

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class scratch_25 {
    static class Reader {
        static BufferedReader reader;
        static StringTokenizer tokenizer;

        /**
         * call this method to initialize reader for InputStream
         */
        static void init(InputStream input) {
            reader = new BufferedReader(
                    new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }

        /**
         * get next word
         */
        static String next() throws IOException {
            while (!tokenizer.hasMoreTokens()) {
                //TODO add check for eof if necessary
                tokenizer = new StringTokenizer(
                        reader.readLine());
            }
            return tokenizer.nextToken();
        }

        static int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        static double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        static long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

    public static class Graph{
        public static class Vertex{
            HashMap<Integer,Integer> nb= new HashMap<>();     // for neighbours of each vertex
        }

        public static HashMap<Integer,Vertex> vt;   // for vertices(all)

        public Graph(){
            vt= new HashMap<>();
        }

        public static int numVer(){
            return vt.size();
        }

        public static boolean contVer(int ver){
            return vt.containsKey(ver);
        }

        public static void addVer(int ver){
            Vertex v= new Vertex();
            vt.put(ver,v);
        }

        public static int numEdg(){
            int count=0;
            ArrayList<Integer> vrtc= new ArrayList<>(vt.keySet());
            for (int i = 0; i <vrtc.size() ; i++) {
                count+=(vt.get(vrtc.get(i))).nb.size();
            }
            return count/2;
        }

        public static boolean contEdg(int ver1, int ver2){
            if(vt.get(ver1)==null || vt.get(ver2)==null){
                return false;
            }

            Vertex v= vt.get(ver1);
            if(v.nb.containsKey(ver2)){
                return true;
            }
            return false;
        }

        public static void addEdge(int ver1, int ver2, int weight){
            if(!vt.containsKey(ver1) || !vt.containsKey(ver2)){
                return;
            }
            Vertex v1= vt.get(ver1);
            Vertex v2= vt.get(ver2);
            v1.nb.put(ver2,weight);                                 // if previously there is an edge, then this replaces that edge
            v2.nb.put(ver1,weight);
        }

        public static void delEdge(int ver1, int ver2){

            if(!vt.containsKey(ver1) || !vt.containsKey(ver2)){
                return;
            }

            vt.get(ver1).nb.remove(ver2);
            vt.get(ver2).nb.remove(ver1);

        }

        public static void delVer(int ver){
            if(!vt.containsKey(ver)){
                return;
            }
            Vertex v1= vt.get(ver);
            ArrayList<Integer> arr= new ArrayList<>(v1.nb.keySet());
            for (int i = 0; i <arr.size() ; i++) {
                int s= arr.get(i);
                vt.get(s).nb.remove(ver);
            }
            vt.remove(ver);
        }

        public class Pair{
            int vname;
            ArrayList<Integer> psf= new ArrayList<>();       // path so far
            int dis;
            int col;
        }

        public HashMap<Integer,Integer> bfs(int src){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> queue= new LinkedList<>();      // for bfs queue

            Pair strtp= new Pair();

            strtp.vname= src;

            ArrayList<Integer> ar= new ArrayList<>();
            ar.add(src);

            strtp.psf= ar;
            strtp.dis=0;

            queue.addLast(strtp);

            while(!queue.isEmpty()){

                Pair rp =  queue.removeFirst();

                if(prcd.containsKey(rp.vname)){
                    continue;
                }
                prcd.put(rp.vname,true);
                ans.put(rp.vname,rp.dis);

//                if(contEdg(rp.vname,dst)){
//                    return true;
//                }

                Vertex a= vt.get(rp.vname);
                ArrayList<Integer> arr= new ArrayList<>(a.nb.keySet());
                for (int i = 0; i <arr.size() ; i++) {
                    int s= arr.get(i);
                    if(!prcd.containsKey(s)){
                        Pair np = new Pair();
                        np.vname= s;
                        np.dis+=rp.dis+a.nb.get(s);
                        np.psf.addAll(rp.psf);
                        np.psf.add(s);
//                        np.psf.add(s);
//                         np.psf= rp.psf+" "+s;
                        queue.addLast(np);
                    }

                }
            }
            return ans;

            //   return false;
        }

        public HashMap<Integer,Integer> dfs(int src){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> stack= new LinkedList<>();      // for bfs queue

            Pair strtp= new Pair();

            strtp.vname= src;

            ArrayList<Integer> ar= new ArrayList<>();
            ar.add(src);

            strtp.psf= ar;
            strtp.dis=0;

            stack.addFirst(strtp);

            while(!stack.isEmpty()){

                Pair rp =  stack.removeFirst();

                if(prcd.containsKey(rp.vname)){
                    continue;
                }
                prcd.put(rp.vname,true);
                ans.put(rp.vname,rp.dis);

//                if(contEdg(rp.vname,dst)){
//                    return true;
//                }

                Vertex a= vt.get(rp.vname);
                ArrayList<Integer> arr= new ArrayList<>(a.nb.keySet());
                for (int i = 0; i <arr.size() ; i++) {
                    int s= arr.get(i);
                    if(!prcd.containsKey(s)){
                        Pair np = new Pair();
                        np.vname= s;
                        np.dis+=rp.dis+a.nb.get(s);
                        np.psf.addAll(rp.psf);
                        np.psf.add(s);
//                        np.psf.add(s);
//                         np.psf= rp.psf+" "+s;
                        stack.addFirst(np);
                    }

                }
            }
            return ans;

            //   return false;
        }

        public boolean isCycle(){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            //   HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> queue= new LinkedList<>();      // for bfs queue

            ArrayList<Integer> keys = new ArrayList<>(vt.keySet());
            for (int i = 0; i <keys.size(); i++) {
                int cur= keys.get(i);
                if(prcd.containsKey(cur)){
                    continue;
                }

                Pair sp = new Pair();
                sp.vname= cur;
                ArrayList<Integer> as= new ArrayList<>();
                as.add(cur);
                sp.psf= as;

                queue.addLast(sp);

                while(!queue.isEmpty()){

                    Pair rp= queue.removeFirst();
                    if(prcd.containsKey(rp.vname)){
                        return true;
                    }

                    prcd.put(rp.vname,true);

                    Vertex v1= vt.get(rp.vname);
                    ArrayList<Integer> nbrs= new ArrayList<>(v1.nb.keySet());
                    for (int j = 0; j <nbrs.size() ; j++) {
                        int u= nbrs.get(j);
                        Pair np= new Pair();
                        np.vname= u;
                        queue.addLast(np);
                    }
                }

            }
            return false;
        }

        public  ArrayList<ArrayList<Integer>> genConnctdComp(){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            ArrayList<ArrayList<Integer>> ans= new ArrayList<>();

            //   HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> queue= new LinkedList<>();      // for bfs queue

            //  int con=-1;

            ArrayList<Integer> keys = new ArrayList<>(vt.keySet());
            for (int i = 0; i <keys.size(); i++) {
                int cur= keys.get(i);
                if(prcd.containsKey(cur)){
                    //return true;
                    continue;
                }
                ArrayList<Integer> fu= new ArrayList<>();
                fu.add(cur);

                Pair sp = new Pair();
                sp.vname= cur;
                ArrayList<Integer> as= new ArrayList<>();
                as.add(cur);
                sp.psf= as;

                queue.addLast(sp);

                while(!queue.isEmpty()){

                    Pair rp= queue.removeFirst();
                    if(prcd.containsKey(rp.vname)){
                        //return true;
                        continue;
                    }

                    prcd.put(rp.vname,true);
                    fu.add(cur);

                    Vertex v1= vt.get(rp.vname);
                    ArrayList<Integer> nbrs= new ArrayList<>();
                    for (int j = 0; j <nbrs.size() ; j++) {
                        int u= nbrs.get(j);
                        Pair np= new Pair();
                        np.vname= u;
                        queue.addLast(np);
                    }
                }
                ans.add(fu);

            }
            //return false;
            return ans;

        }

        public boolean isBip(int src){                       // only for connected graph

            HashMap<Integer,Integer> clr= new HashMap<>();
            // colors are 1 and -1

            LinkedList<Integer>q = new LinkedList<Integer>();
            clr.put(src,1);
            q.add(src);

            while(!q.isEmpty()){

                int u = q.getFirst();
                q.pop();

                ArrayList<Integer> arr= new ArrayList<>(vt.keySet());

                for (int i = 0; i <arr.size() ; ++i) {

                    int x= arr.get(i);

                    if(vt.get(u).nb.containsKey(x) && !clr.containsKey(x)){

                        if(clr.get(u)==1){
                            clr.put(x,-1);
                        }
                        else{
                            clr.put(x,1);
                        }
                        q.push(x);
                    }

                    else if(vt.get(u).nb.containsKey(x) && (clr.get(x)==clr.get(u))){
                        return false;
                    }

                }
            }
            return true;
        }

        public static void printGr() {
            ArrayList<Integer> arr= new ArrayList<>(vt.keySet());
            for (int i = 0; i <arr.size() ; i++) {
                int ver= arr.get(i);
                Vertex v1= vt.get(ver);
                ArrayList<Integer> arr1= new ArrayList<>(v1.nb.keySet());
                for (int j = 0; j <arr1.size() ; j++) {
                    System.out.println(ver+"-"+arr1.get(j)+":"+v1.nb.get(arr1.get(j)));
                }

            }
        }
    }

    public static void main(String[] args)  throws IOException {
        Reader.init(System.in);
        int t = Reader.nextInt();
        for (int j = 0; j < t; j++) {
            int n= Reader.nextInt();
            char arr[]= Reader.next().toCharArray();
            int x= good(arr,n,97);
            System.out.println(x);

        }

    }

    public static int good(char arr[],int n, int ac){
        if(n==1){
            if((int)arr[0]==ac){
                return 0;
            }
            else{
                return 1;
            }
        }
        int mid= arr.length/2;
        int count=0;
        int count1=0;
        for (int i = 0; i <mid ; i++) {
            char c= arr[i];
            int num= (int)c;
            if(num!=ac){
                count++;
            }
        }
        for (int i = mid; i <arr.length ; i++) {
            char c= arr[i];
            int num= (int)c;
            if(num!=ac){
                count1++;
            }
        }
        if(count>count1){
            return count1+good(Arrays.copyOfRange(arr,0,mid),n/2,ac+1);
        }
        else{
            return count+good(Arrays.copyOfRange(arr,mid,n),n/2,ac+1);
        }

    }

    public static ArrayList<Integer> Sieve(int n) {
        boolean arr[]= new boolean [n+1];
        Arrays.fill(arr,true);
        arr[0]=false;
        arr[1]=false;
        for (int i = 2; i*i <=n ; i++) {
            if(arr[i]==true){
                for (int j = 2; j <=n/i ; j++) {
                    int u= i*j;
                    arr[u]=false;
                }}
        }
        ArrayList<Integer> ans= new ArrayList<>();
        for (int i = 0; i <n+1 ; i++) {
            if(arr[i]){
                ans.add(i);
            }
        }
        return ans;

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class scratch_25 {
    static class Reader {
        static BufferedReader reader;
        static StringTokenizer tokenizer;

        /**
         * call this method to initialize reader for InputStream
         */
        static void init(InputStream input) {
            reader = new BufferedReader(
                    new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }

        /**
         * get next word
         */
        static String next() throws IOException {
            while (!tokenizer.hasMoreTokens()) {
                //TODO add check for eof if necessary
                tokenizer = new StringTokenizer(
                        reader.readLine());
            }
            return tokenizer.nextToken();
        }

        static int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        static double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        static long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

    public static class Graph{
        public static class Vertex{
            HashMap<Integer,Integer> nb= new HashMap<>();     // for neighbours of each vertex
        }

        public static HashMap<Integer,Vertex> vt;   // for vertices(all)

        public Graph(){
            vt= new HashMap<>();
        }

        public static int numVer(){
            return vt.size();
        }

        public static boolean contVer(int ver){
            return vt.containsKey(ver);
        }

        public static void addVer(int ver){
            Vertex v= new Vertex();
            vt.put(ver,v);
        }

        public static int numEdg(){
            int count=0;
            ArrayList<Integer> vrtc= new ArrayList<>(vt.keySet());
            for (int i = 0; i <vrtc.size() ; i++) {
                count+=(vt.get(vrtc.get(i))).nb.size();
            }
            return count/2;
        }

        public static boolean contEdg(int ver1, int ver2){
            if(vt.get(ver1)==null || vt.get(ver2)==null){
                return false;
            }

            Vertex v= vt.get(ver1);
            if(v.nb.containsKey(ver2)){
                return true;
            }
            return false;
        }

        public static void addEdge(int ver1, int ver2, int weight){
            if(!vt.containsKey(ver1) || !vt.containsKey(ver2)){
                return;
            }
            Vertex v1= vt.get(ver1);
            Vertex v2= vt.get(ver2);
            v1.nb.put(ver2,weight);                                 // if previously there is an edge, then this replaces that edge
            v2.nb.put(ver1,weight);
        }

        public static void delEdge(int ver1, int ver2){

            if(!vt.containsKey(ver1) || !vt.containsKey(ver2)){
                return;
            }

            vt.get(ver1).nb.remove(ver2);
            vt.get(ver2).nb.remove(ver1);

        }

        public static void delVer(int ver){
            if(!vt.containsKey(ver)){
                return;
            }
            Vertex v1= vt.get(ver);
            ArrayList<Integer> arr= new ArrayList<>(v1.nb.keySet());
            for (int i = 0; i <arr.size() ; i++) {
                int s= arr.get(i);
                vt.get(s).nb.remove(ver);
            }
            vt.remove(ver);
        }

        public class Pair{
            int vname;
            ArrayList<Integer> psf= new ArrayList<>();       // path so far
            int dis;
            int col;
        }

        public HashMap<Integer,Integer> bfs(int src){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> queue= new LinkedList<>();      // for bfs queue

            Pair strtp= new Pair();

            strtp.vname= src;

            ArrayList<Integer> ar= new ArrayList<>();
            ar.add(src);

            strtp.psf= ar;
            strtp.dis=0;

            queue.addLast(strtp);

            while(!queue.isEmpty()){

                Pair rp =  queue.removeFirst();

                if(prcd.containsKey(rp.vname)){
                    continue;
                }
                prcd.put(rp.vname,true);
                ans.put(rp.vname,rp.dis);

//                if(contEdg(rp.vname,dst)){
//                    return true;
//                }

                Vertex a= vt.get(rp.vname);
                ArrayList<Integer> arr= new ArrayList<>(a.nb.keySet());
                for (int i = 0; i <arr.size() ; i++) {
                    int s= arr.get(i);
                    if(!prcd.containsKey(s)){
                        Pair np = new Pair();
                        np.vname= s;
                        np.dis+=rp.dis+a.nb.get(s);
                        np.psf.addAll(rp.psf);
                        np.psf.add(s);
//                        np.psf.add(s);
//                         np.psf= rp.psf+" "+s;
                        queue.addLast(np);
                    }

                }
            }
            return ans;

            //   return false;
        }

        public HashMap<Integer,Integer> dfs(int src){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> stack= new LinkedList<>();      // for bfs queue

            Pair strtp= new Pair();

            strtp.vname= src;

            ArrayList<Integer> ar= new ArrayList<>();
            ar.add(src);

            strtp.psf= ar;
            strtp.dis=0;

            stack.addFirst(strtp);

            while(!stack.isEmpty()){

                Pair rp =  stack.removeFirst();

                if(prcd.containsKey(rp.vname)){
                    continue;
                }
                prcd.put(rp.vname,true);
                ans.put(rp.vname,rp.dis);

//                if(contEdg(rp.vname,dst)){
//                    return true;
//                }

                Vertex a= vt.get(rp.vname);
                ArrayList<Integer> arr= new ArrayList<>(a.nb.keySet());
                for (int i = 0; i <arr.size() ; i++) {
                    int s= arr.get(i);
                    if(!prcd.containsKey(s)){
                        Pair np = new Pair();
                        np.vname= s;
                        np.dis+=rp.dis+a.nb.get(s);
                        np.psf.addAll(rp.psf);
                        np.psf.add(s);
//                        np.psf.add(s);
//                         np.psf= rp.psf+" "+s;
                        stack.addFirst(np);
                    }

                }
            }
            return ans;

            //   return false;
        }

        public boolean isCycle(){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            //   HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> queue= new LinkedList<>();      // for bfs queue

            ArrayList<Integer> keys = new ArrayList<>(vt.keySet());
            for (int i = 0; i <keys.size(); i++) {
                int cur= keys.get(i);
                if(prcd.containsKey(cur)){
                    continue;
                }

                Pair sp = new Pair();
                sp.vname= cur;
                ArrayList<Integer> as= new ArrayList<>();
                as.add(cur);
                sp.psf= as;

                queue.addLast(sp);

                while(!queue.isEmpty()){

                    Pair rp= queue.removeFirst();
                    if(prcd.containsKey(rp.vname)){
                        return true;
                    }

                    prcd.put(rp.vname,true);

                    Vertex v1= vt.get(rp.vname);
                    ArrayList<Integer> nbrs= new ArrayList<>(v1.nb.keySet());
                    for (int j = 0; j <nbrs.size() ; j++) {
                        int u= nbrs.get(j);
                        Pair np= new Pair();
                        np.vname= u;
                        queue.addLast(np);
                    }
                }

            }
            return false;
        }

        public  ArrayList<ArrayList<Integer>> genConnctdComp(){
            HashMap<Integer, Boolean> prcd= new HashMap<>();    // jo jo ho chuke hain unke liye

            ArrayList<ArrayList<Integer>> ans= new ArrayList<>();

            //   HashMap<Integer, Integer> ans= new HashMap<>();

            LinkedList<Pair> queue= new LinkedList<>();      // for bfs queue

            //  int con=-1;

            ArrayList<Integer> keys = new ArrayList<>(vt.keySet());
            for (int i = 0; i <keys.size(); i++) {
                int cur= keys.get(i);
                if(prcd.containsKey(cur)){
                    //return true;
                    continue;
                }
                ArrayList<Integer> fu= new ArrayList<>();
                fu.add(cur);

                Pair sp = new Pair();
                sp.vname= cur;
                ArrayList<Integer> as= new ArrayList<>();
                as.add(cur);
                sp.psf= as;

                queue.addLast(sp);

                while(!queue.isEmpty()){

                    Pair rp= queue.removeFirst();
                    if(prcd.containsKey(rp.vname)){
                        //return true;
                        continue;
                    }

                    prcd.put(rp.vname,true);
                    fu.add(cur);

                    Vertex v1= vt.get(rp.vname);
                    ArrayList<Integer> nbrs= new ArrayList<>();
                    for (int j = 0; j <nbrs.size() ; j++) {
                        int u= nbrs.get(j);
                        Pair np= new Pair();
                        np.vname= u;
                        queue.addLast(np);
                    }
                }
                ans.add(fu);

            }
            //return false;
            return ans;

        }

        public boolean isBip(int src){                       // only for connected graph

            HashMap<Integer,Integer> clr= new HashMap<>();
            // colors are 1 and -1

            LinkedList<Integer>q = new LinkedList<Integer>();
            clr.put(src,1);
            q.add(src);

            while(!q.isEmpty()){

                int u = q.getFirst();
                q.pop();

                ArrayList<Integer> arr= new ArrayList<>(vt.keySet());

                for (int i = 0; i <arr.size() ; ++i) {

                    int x= arr.get(i);

                    if(vt.get(u).nb.containsKey(x) && !clr.containsKey(x)){

                        if(clr.get(u)==1){
                            clr.put(x,-1);
                        }
                        else{
                            clr.put(x,1);
                        }
                        q.push(x);
                    }

                    else if(vt.get(u).nb.containsKey(x) && (clr.get(x)==clr.get(u))){
                        return false;
                    }

                }
            }
            return true;
        }

        public static void printGr() {
            ArrayList<Integer> arr= new ArrayList<>(vt.keySet());
            for (int i = 0; i <arr.size() ; i++) {
                int ver= arr.get(i);
                Vertex v1= vt.get(ver);
                ArrayList<Integer> arr1= new ArrayList<>(v1.nb.keySet());
                for (int j = 0; j <arr1.size() ; j++) {
                    System.out.println(ver+"-"+arr1.get(j)+":"+v1.nb.get(arr1.get(j)));
                }

            }
        }
    }

    public static void main(String[] args)  throws IOException {
        Reader.init(System.in);
        int t = Reader.nextInt();
        for (int j = 0; j < t; j++) {
            int n= Reader.nextInt();
            char arr[]= Reader.next().toCharArray();
            int x= good(arr,n,97);
            System.out.println(x);

        }

    }

    public static int good(char arr[],int n, int ac){
        if(n==1){
            if((int)arr[0]==ac){
                return 0;
            }
            else{
                return 1;
            }
        }
        int mid= arr.length/2;
        int count=0;
        int count1=0;
        for (int i = 0; i <mid ; i++) {
            char c= arr[i];
            int num= (int)c;
            if(num!=ac){
                count++;
            }
        }
        for (int i = mid; i <arr.length ; i++) {
            char c= arr[i];
            int num= (int)c;
            if(num!=ac){
                count1++;
            }
        }

            return Math.min( count1+good(Arrays.copyOfRange(arr,0,mid),n/2,ac+1),count+good(Arrays.copyOfRange(arr,mid,n),n/2,ac+1));

    }

    public static ArrayList<Integer> Sieve(int n) {
        boolean arr[]= new boolean [n+1];
        Arrays.fill(arr,true);
        arr[0]=false;
        arr[1]=false;
        for (int i = 2; i*i <=n ; i++) {
            if(arr[i]==true){
                for (int j = 2; j <=n/i ; j++) {
                    int u= i*j;
                    arr[u]=false;
                }}
        }
        ArrayList<Integer> ans= new ArrayList<>();
        for (int i = 0; i <n+1 ; i++) {
            if(arr[i]){
                ans.add(i);
            }
        }
        return ans;

    }

}


import java.io.*;
import java.util.*;

public class GFG {
	public static void main (String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
		    int n=sc.nextInt();
		    String str=sc.next();
		    int res=Integer.MAX_VALUE;
		    for(int i=0;i<n;i++)
		    {
		        if(res>(str.charAt(i)+0))
		        res=str.charAt(i)+0;
		    }
		    int k=rec(str,0,n-1,(char)res);
		    System.out.println(k);
		}
	}
	public static int rec( String str,int s,int e,char c)
	{
	    if(s==e)
	    {
	        if(str.charAt(s)!=c)
	        return 1;
	        return 0;
	    }
	    if(s>e)
	    {

	        return 0;
	    }

	    int count1=0;
	    int count2=0;
	    for(int i=s;i<(e-s+1)/2;i++ )
	    {
	        if(str.charAt(i)!=c)
	        count1++;
	    }
	    for(int i=(e-s+1)/2;i<=e;i++)
	    {
	        if(str.charAt(i)!=c)
	        count2++;
	    }
	    return Math.min(count1+rec(str,(e-s+1)/2,e,(char)(c+1)),count2+rec(str,s,((e-s+1)/2)-1,(char)(c+1)));
	}
}


/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;

public class GFG {
	public static void main (String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
		    int n=sc.nextInt();
		    String str=sc.next();
		    int res=Integer.MAX_VALUE;
		    for(int i=0;i<n;i++)
		    {
		        if(res>(str.charAt(i)+0))
		        res=str.charAt(i)+0;
		    }
		    int k=rec(str,0,n-1,(char)res);
		    System.out.println(k);
		}
	}
	public static int rec( String str,int s,int e,char c)
	{

	    if(s==e)
	    {
	        if(str.charAt(s)!=c)
	        return 1;
	        return 0;
	    }
	    if(s>e)
	    {

	        return 0;
	    }

	    int count1=0;
	    int count2=0;
	    for(int i=s;i<s+(e-s+1)/2;i++ )
	    {
	        if(str.charAt(i)!=c)
	        count1++;
	    }
	    for(int i=s+(e-s+1)/2;i<=e;i++)
	    {
	        if(str.charAt(i)!=c)
	        count2++;
	    }

	    return Math.min( (count1+rec(str,s+(e-s+1)/2,e,(char)(c+1))),
	                      (count2+rec(str,s,s+((e-s+1)/2)-1,(char)(c+1))));

	}
}


/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;

public class GFG {
	public static void main (String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
		    int n=sc.nextInt();
		    String str=sc.next();
		    int res=Integer.MAX_VALUE;
		    for(int i=0;i<n;i++)
		    {
		        if(res>(str.charAt(i)+0))
		        res=str.charAt(i)+0;
		    }
		    int k=rec(str,0,n-1,'a');
		    System.out.println(k);
		}
	}
	public static int rec( String str,int s,int e,char c)
	{

	    if(s==e)
	    {
	        if(str.charAt(s)!=c)
	        return 1;
	        return 0;
	    }
	    if(s>e)
	    {

	        return 0;
	    }

	    int count1=0;
	    int count2=0;
	    for(int i=s;i<s+(e-s+1)/2;i++ )
	    {
	        if(str.charAt(i)!=c)
	        count1++;
	    }
	    for(int i=s+(e-s+1)/2;i<=e;i++)
	    {
	        if(str.charAt(i)!=c)
	        count2++;
	    }

	    return Math.min( (count1+rec(str,s+(e-s+1)/2,e,(char)(c+1))),
	                      (count2+rec(str,s,s+((e-s+1)/2)-1,(char)(c+1))));

	}
}