#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
from itertools import *
import random
import math
# MOD = 998244353
MOD = 10**9 + 7
inf = float("inf")
def solve():
N, K = rlist()
orda = ord("a")
A = [ord(c) - orda for c in input()]
cost = [0] * (N - 2)
for i in range(N - 2):
cur_cost = 0
for j in range(3):
x = A[i + j]
if x == j:
continue
elif x > j:
cur_cost += 26 + j - x
else:
cur_cost += j - x
cost[i] = cur_cost
dp = [[inf] * (N // 3 + 1) for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0] = 0
for i in range(N - 3, -1, -1):
for s in range(N // 3, 0, -1):
dp[i][s] = min(dp[i + 1][s], dp[i + 3][s - 1] + cost[i])
for s in range(N // 3, -1, -1):
if dp[0][s] <= K:
return s
def main():
T = 1
T = rint()
for tc in range(1, 1 + T):
ans = solve()
print(ans)
# print(*ans)
# print("Yes" if ans else "No")
# print("YES" if ans else "NO")
# print("Alice" if ans else "Bob")
# print("First" if ans else "Second")
# print("Case #{}: {}".format(tc, ans))
# print(len(ans))
# for row in ans: print(*row)
rint = lambda: int(input())
def rlist():
return list(map(int, input().split()))
def rgrid(n):
return [rlist() for _ in range(n)]
# endregion
if __name__ == "__main__":
main()