#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;
    int cWins = 0;
    vector<int> closs;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'W') {
        w++;
        if (i == 0 || s[i - 1] == 'L') cWins++;
      }
      if (s[i] == 'L') {
        l++;
        if (i == 0 || s[i - 1] == 'W') closs.push_back(0);
        closs.back()++;
      }
    }
    if (k >= l) {
      cout << 2 * n - 1 << "\n";
      continue;
    } else if (w == 0) {
      if (k == 0)
        cout << 0 << "\n";
      else
        cout << 2 * k - 1 << "\n";
      continue;
    }
    if (s[0] == 'L') closs[0] = 1e8;
    if (s[n - 1] == 'L') closs.back() = 1e8;
    sort(closs.begin(), closs.end());
    w += k;
    for (int x : closs) {
      if (x > k) break;
      k -= x;
      cWins--;
    }
    cout << 2 * w - cWins << "\n";
  }
  return 0;
}
