#include <bits/stdc++.h>
using namespace std;
#define SC scanf
#define PF printf
#define ull unsigned long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sort_a(a) sort(a.begin(),a.end());
#define sort_d(a) sort(a.rbegin(),a.rend());
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define rev(s) reverse(s.begin(),s.end())
#define P(ok) cout << (ok ? "YES\n": "NO\n")
#define __Heart__ ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll> PII;
const int sz= 5e3 + 5 ;
void solve()
{
int make_A[sz] , make_B[sz] , make_C[sz] , substringCost[sz] , n , k , Ans = 0;
string s ;
cin >> n >> k >> s ;
for(int i = 0 ; i < n ; i++){
make_A[i] = (122 - s[i] + 1) % 26 ;
make_B[i] = (122 - s[i] + 2) % 26 ;
make_C[i] = (122 - s[i] + 3) % 26 ;
}
for(int i = 0 ; i <= n - 3 ; i++) {
substringCost[i] = make_A[i] + make_B[i + 1] + make_C[i + 2] ;
}
vector<int> dp(k + 1, 0);
dp[0] = 0;
for (int i = 0; i <= n - 3 ; i++) {
for(int j = k ; j >= substringCost[i] ; j--){
dp[j] = max(dp[j] , dp[j - substringCost[i]] + 1) ;
}
}
cout << dp[k] << "\n" ;
}
int main()
{
__Heart__
int t ; cin >> t ; while(t--) solve() ;
}