#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  deque<int> dq;
  string s;
  cin >> s;
  long long wins = 0, loses = 0;
  int w_streak = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'L') {
      loses++;
    }
    if (s[i] == 'W') {
      wins++;
      if (i == 0 || s[i - 1] == 'L') w_streak++;
    }
  }
  if (loses <= k) {
    cout << 2 * n - 1 << "\n";
    return;
  }
  int i = 0;
  while (i < n) {
    if (s[i] == 'L') {
      int l = 0;
      while (s[i] == 'L' && i < n) {
        l++;
        i++;
      }
      dq.push_back(l);
    } else
      i++;
  }
  int starting_loses = 0, ending_loses = 0;
  if (s[0] == 'L') {
    starting_loses = dq[0];
    dq.pop_front();
  }
  if (s[n - 1] == 'L' && w_streak) {
    ending_loses = dq[dq.size() - 1];
    dq.pop_back();
  }
  vector<int> v;
  for (auto x : dq) v.push_back(x);
  sort(v.begin(), v.end());
  for (auto x : v) {
    if (x <= k) {
      k -= x;
      w_streak -= 1;
      wins += x;
    } else {
      wins += k;
      k = 0;
    }
  }
  if (loses == n && k > 0) w_streak++;
  if (k) wins += k;
  cout << 2 * wins - w_streak << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
