#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define error1(x) cerr<<#x<<" = "<<(x)<<endl
#define error2(a,b) cerr<<"("<<#a<<", "<<#b<<") = ("<<(a)<<", "<<(b)<<")\n";
#define coutall(v) for(auto &it: v) cout << it << " "; cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
const int inf = 1e9;
void solve() {
ll n, k;
string s1;
cin >> n >> k >> s1;
auto cost = [&](char now, char target) -> int {
if(now <= target) return target - now;
return ('z' - now) + (target - 'a') + 1;
};
vector<vector<int>> dp(n + 1, vector<int> (n + 1, -1));
auto rec = [&] (auto&& self, int i, int make) -> int {
if(i + 2 >= n) return (make == 0 ? 0 : inf);
auto& ans = dp[i][make];
if(ans != -1) return ans;
ans = self(self, i + 1, make);
if(make > 0) ans = min(ans, cost(s1[i], 'a') + cost(s1[i + 1], 'b') + cost(s1[i + 2], 'c') + self(self,i + 3, make - 1));
return ans >= inf ? inf : ans;
};
for(int i = n / 3; i >= 1; i--) {
if(rec(rec, 0, i) <= k) {
cout << i << endl;
return;
}
}
cout << 0 << endl;
return;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int tc = 1;
cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case " << t << ": ";
solve();
}
return 0;
}