#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cntL = count(s.begin(), s.end(), 'L');
    if (cntL == n) {
      cout << max(2 * k - 1, 0) << "\n";
      continue;
    }
    vector<int> posW;
    for (int i = 0; i < n; i++)
      if (s[i] == 'W') posW.push_back(i);
    vector<int> seg;
    for (int i = 1; i < int(posW.size()); i++)
      if (posW[i] - posW[i - 1] - 1 > 0)
        seg.push_back(posW[i] - posW[i - 1] - 1);
    int ans = s[0] == 'W';
    for (int i = 1; i < n; i++)
      if (s[i] == 'W') ans += s[i - 1] == 'W' ? 2 : 1;
    ans += 2 * min(k, cntL);
    sort(seg.begin(), seg.end());
    for (auto len : seg)
      if (k >= len) k -= len, ans += 1;
    cout << ans << "\n";
  }
  return 0;
}
