#include<bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define prime_number[21]={11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}
///POLICY BASED DATA STRUCTURE..
///order_of_key return number of element which are strictly greater/smaller than x..
///find_by_order return ans iterator corresponding to the xth position of the set..
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define faster_bro ios_base::sync_with_stdio(false);cin.tie(NULL)
#define esp 0.0000000001
#define ss second
#define ff first
#define nl cout<<endl
//memset(ar,-1,sizeof(ar));
// (1LL<<i) more than efficient pow(2,i);
void fast(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main(){
fast();
int tc;
cin>>tc;
int h=1;
while(tc--){
ll a,b,c,sum=0,sum1=0,sum2=0,cnt=0,mx=LLONG_MIN,mn=LLONG_MAX,mx1=-1e18,mx2=-1e18;
cin>>a>>b;
string s;
cin>>s;
char c1='z';
ll lagbe;
set<int>st;
int j=1;
map<char,int>mp;
for(char i='a';i<='z';i++){
mp[i]=j;
j++;
}
int l=mp['z'];
for(int i=0;i<a-2;i++){
// cout<<i<<" ";
int f=0;
int pos;
mn=INT_MAX;
if(st.find(i)!=st.end()){
continue;
}
if(s[i]=='a' && s[i+1]=='b' && s[i+2]=='c'){
st.insert(i);
st.insert(i+1);
st.insert(i+2);
i+=2;
continue;
}
for(int j=0;j<a-2;j++){
if(st.find(j)!=st.end()){
continue;
}
int k1=mp[s[j]];
int k11;
if(s[j]=='a'){
k11=0;
}
else{
k11=(l-k1+1);
}
int k2=mp[s[j+1]];
int k22;
if(s[j+1]=='b'){
k22=0;
}
else{
if(s[j+1]<'b'){
k22=mp['b'] - mp[s[j+1]];
}
else
k22=(l-k2+2);
}
int k3=mp[s[j+2]];
int k33;
if(s[j+2]=='c'){
k33=0;
}
else{
if(s[j+2]<'c'){
k33=mp['c'] - mp[s[j+2]];
}
else
k33=(l-k3+3);
}
// cout<<k1<<" "<<k2<<" "<<k3<<endl;
lagbe=k11 + k22 + k33;
//cout<<lagbe<<" ";
if(lagbe<=b){
f=1;
if(lagbe<mn){
mn=lagbe;
pos=j;
}
}
}
// cout<<endl;
//cout<<mn<<" "<<pos<<endl;
if(f==1){
st.insert(pos);
st.insert(pos+1);
st.insert(pos+2);
b-=mn;
s[pos]='a';
s[pos+1]='b';
s[pos+2]='c';
}
}
cnt=0;
for(int i=0;i<a-2;i++){
if(s[i]=='a' && s[i+1]=='b' && s[i+2]=='c'){
cnt++;
i+=2;
}
}
cout<<cnt<<endl;
}
}