#include <bits/stdc++.h>
using namespace std;
int T, N, K;
string stat;
vector<int> v;
void process() {
  int l = 0, r = 0, ans = 0, W_count = 0;
  bool L_Flag = false, W_Flag = false;
  v.clear();
  for (int i = 0; i < N; i++) {
    if (stat[i] == 'W') {
      if (W_Flag)
        ans += 2;
      else {
        ans += 1;
        W_Flag = true;
      }
    } else {
      W_Flag = false;
    }
  }
  if (stat[0] == 'W') W_count++;
  for (int i = 1; i < N; i++) {
    if (stat[i] == 'W') W_count++;
    if (stat[i - 1] == 'W' && stat[i] == 'L') {
      l = i;
      L_Flag = true;
    } else if (L_Flag) {
      if (stat[i] == 'W') {
        v.emplace_back(i - l);
        L_Flag = false;
      }
    }
  }
  int L_count = N - W_count;
  if (K >= L_count) {
    cout << 2 * N - 1 << "\n";
    return;
  }
  if (W_count == 0) {
    cout << std::max(2 * K - 1, 0) << "\n";
    return;
  }
  sort(v.begin(), v.end());
  const int v_size = v.size();
  int ptr = 0;
  while (ptr < v_size && v[ptr] <= K) {
    ans += 2 * v[ptr] + 1;
    K -= v[ptr];
    ptr++;
  }
  if (K > 0) ans += 2 * K;
  cout << ans << "\n";
}
void cf_input() {
  cin >> T;
  for (int t = 0; t < T; t++) {
    cin >> N >> K;
    cin >> stat;
    process();
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cf_input();
  return 0;
}
