#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const long long Mod = 1e9 + 7;
const long long inf = 1e18;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s += '#';
    bool ok = false;
    long long front = 0, back = 0;
    vector<long long> l;
    long long ans = 0;
    long long cntL = 0, cntW = 0;
    for (long long i = 0; i <= n; i++) {
      if (s[i] == 'W')
        cntW++;
      else {
        if (cntW) {
          long long x = 1 + (max(0ll, cntW - 1) * 2);
          ans += x;
          cntW = 0;
        }
      }
    }
    debug() << "\033[0;33mLine(" << 118 << ")\033[0m"
            << "\033[1;36m->"
            << "\033[0m"
            << "\033[94m ["
            << "ans"
               ": "
            << (ans) << "]\033[0m";
    for (long long i = 0; i <= n; i++) {
      if (s[i] == 'L')
        cntL++;
      else {
        if (!ok) {
          front = cntL;
        } else if (s[i] == '#') {
          back = cntL;
        } else if (ok) {
          l.push_back(cntL);
        }
        cntL = 0;
        ok = true;
      }
    }
    debug() << "\033[0;33mLine(" << 134 << ")\033[0m"
            << "\033[1;36m->"
            << "\033[0m"
            << "\033[94m ["
            << "front"
               ": "
            << (front)
            << "]\033[0m"
               "\033[94m ["
            << "back"
               ": "
            << (back) << "]\033[0m";
    debug() << "\033[0;33mLine(" << 135 << ")\033[0m"
            << "\033[1;36m->"
            << "\033[0m"
            << "\033[94m ["
            << "l"
               ": "
            << (l) << "]\033[0m";
    sort(l.begin(), l.end());
    for (long long i = 0; i < (long long)l.size(); i++) {
      if (l[i] == 0) continue;
      if (k <= 0) break;
      if (k < l[i]) break;
      long long x = min(k, l[i]);
      ans += (x * 2) + 1;
      l[i] -= x;
      k -= x;
    }
    debug() << "\033[0;33mLine(" << 146 << ")\033[0m"
            << "\033[1;36m->"
            << "\033[0m"
            << "\033[94m ["
            << "ans"
               ": "
            << (ans)
            << "]\033[0m"
               "\033[94m ["
            << "k"
               ": "
            << (k) << "]\033[0m";
    for (long long i = 0; i < (long long)l.size(); i++) {
      if (k <= 0) break;
      long long x = min(k, l[i]);
      ans += (x + x);
      k -= x;
    }
    long long x = min(k, front + back);
    if (x) {
      if (ans > 0) {
        ans += (x * 2);
      } else {
        ans += 2 * x - 1;
      }
    }
    cout << ans << '\n';
  }
}
