#include <bits/stdc++.h>
using namespace std;
void solve(int test_case) {
  int n, k;
  string S;
  cin >> n >> k >> S;
  int wins = 0;
  for (int i = 0; i < n; ++i) {
    wins += (S[i] == 'W');
  }
  if (n - wins <= k) {
    cout << max(0, 2 * n - 1) << "\n";
    return;
  }
  if (wins == 0) {
    cout << max(0, min(n, k) * 2 - 1) << "\n";
    return;
  }
  vector<int> gaps;
  int trip = 0, st = 0, back = 0;
  for (int i = 0; i < n; ++i) {
    if (S[i] == 'W') {
      trip = 1;
      continue;
    }
    if (trip) {
      int j = i;
      while (i < n && S[i] == 'L') {
        ++i;
      }
      if (i == n)
        back = i - j;
      else
        gaps.push_back(i - j);
    } else {
      while (i < n && S[i] == 'L') {
        ++i;
        ++st;
      }
      trip = 1;
    }
  }
  sort(gaps.begin(), gaps.end());
  int swi = 0, ans = 0;
  for (int i = 0; i < n; ++i) {
    if (S[i] == 'L') {
      swi = 0;
      continue;
    }
    if (swi) {
      ans += 2;
      swi = 1;
    } else {
      ++ans;
      swi = 1;
    }
  }
  for (int i = 0; i < ((int)gaps.size()) && k; ++i) {
    if (k >= gaps[i]) {
      k -= gaps[i];
      ans += gaps[i] * 2 + 1;
    } else {
      ans += 2 * k;
      k = 0;
      break;
    }
  }
  if (k && st) {
    ans += 2 * min(k, st);
    k -= min(k, st);
  }
  if (k && back) {
    ans += 2 * min(k, back);
    k -= min(k, back);
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, test_case = 0;
  cin >> t;
  for (; test_case < t; ++test_case) {
    solve(test_case);
  }
  return 0;
}
