#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int w(0), l(0);
    for (char c : s) {
      if (c == 'W') w++;
    }
    if (k + w >= n) {
      cout << 2 * n - 1 << '\n';
      continue;
    }
    vector<int> gaps;
    for (int i = 0; i < n; ++i) {
      bool good = (i > 0);
      if (s[i] == 'W') {
        continue;
      }
      int len = 1;
      while (i + 1 < n && s[i + 1] == 'L') {
        len++;
        i++;
      }
      if (good && i != n - 1) {
        gaps.push_back(len);
      }
    }
    sort(gaps.begin(), gaps.end());
    int ans(0), rem(0);
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'W')
        ans++;
      else
        rem++;
      if (s[i] == 'W' && i > 0 && s[i - 1] == 'W') ans++;
    }
    if (rem == n && k > 0) ans--;
    for (int x : gaps) {
      if (k >= x) {
        k -= x;
        ans += 2 * x + 1;
        rem -= x;
      } else {
        break;
      }
    }
    ans += 2 * min(k, rem);
    cout << ans << '\n';
  }
  return 0;
}
