// PIPRA || HABIB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define pb push_back
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define endl "\n"
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) {
os << '{';
for (const auto &x : v) os << " " << x;
return os << '}';
}
using orderedTree = tree<int, null_type, less<int>,
rb_tree_tag, tree_order_statistics_node_update>;
const int N = 5000;
const int M = 30000;
const int inf = -1e8;
int n;
string s;
vector<vector<int>> dp(N, vector<int>(M, -1));
int recur(int i, int k){
if(i >= (n-2)) return 0;
if(k < 0) return inf;
int &ans = dp[i][k];
if(ans != -1) return dp[i][k];
ans = recur(i+1, k);
int ind = i;
int cost = 0;
for(char i='a' ; i<='c' ; i++){
if(s[ind] <= i){
cost += i - s[ind];
}
else{
cost += 'z' - s[ind] + (i - 'a' + 1);
}
}
// cout << i << ' ' << cost << endl;
ans = max(ans, recur(i+3, k - cost) + 1);
return ans;
}
void pipra(){
int k;
cin >> n >> k;
cin >> s;
cout << recur(0, k) << endl;
}
int32_t main(){
// HABIB
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t; cin>>t;
while(t--) {
pipra();
}
return 0 ;
}