#include <bits/stdc++.h>
using namespace std;
void sol() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long w = 0;
  for (auto el : s) {
    if (el == 'W') {
      w++;
    }
  }
  vector<long long> rofl;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'W') {
      rofl.push_back(i);
    }
  }
  vector<pair<long long, long long>> kek;
  for (long long i = 1; i < (long long)rofl.size(); i++) {
    long long left = rofl[i - 1], right = rofl[i];
    kek.emplace_back(right - left + 1, left);
  }
  sort(kek.begin(), kek.end());
  for (auto pp : kek) {
    long long len = pp.first, l = pp.second;
    for (long long i = l; i < l + len; i++) {
      if (k > 0 && s[i] == 'L') {
        s[i] = 'W';
        k--;
      }
    }
  }
  if (rofl.empty()) {
    rofl.push_back(0);
  }
  for (long long i = rofl.back(); i < n; i++) {
    if (k > 0 && s[i] == 'L') {
      k--;
      s[i] = 'W';
    }
  }
  for (long long i = rofl.back(); i >= 0; i--) {
    if (k > 0 && s[i] == 'L') {
      k--;
      s[i] = 'W';
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'W') {
      if (i == 0 || s[i - 1] == 'L') {
        ans++;
      } else {
        ans += 2;
      }
    }
  }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long t = 1;
  cin >> t;
  while (t--) {
    sol();
  }
}
