#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    string s;
    cin >> s;
    vector<pair<char, int>> v;
    for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
      if (!int(v.size()) || v.back().first != s[i])
        v.push_back({s[i], 1});
      else
        v.back().second++;
    }
    vector<pair<int, int>> rem;
    for (int i = 1, ThxDem = int(v.size()) - 1; i < ThxDem; ++i) {
      if (v[i].first == 'L') rem.push_back({v[i].second, i});
    }
    sort(rem.begin(), rem.end());
    for (int i = 0, ThxDem = int(rem.size()); i < ThxDem; ++i) {
      if (rem[i].first <= k) {
        v[rem[i].second].first = 'W';
        k -= rem[i].first;
      } else {
        int now = k;
        v[rem[i].second].second -= k;
        pair<char, int> noww = {'W', k};
        int off = rem[i].second != int(v.size()) - 1;
        v.insert(v.begin() + rem[i].second + off, noww);
        k = 0;
        break;
      }
    }
    if (v[0].first == 'L') {
      if (v[0].second <= k)
        v[0].first = 'W', k -= v[0].second;
      else if (k) {
        int now = k;
        v[0].second -= k;
        pair<char, int> noww = {'W', k};
        v.insert(v.begin() + 1, noww);
        k = 0;
      }
    }
    int xx = int(v.size()) - 1;
    if (v[xx].first == 'L') {
      if (v[xx].second <= k)
        v[xx].first = 'W';
      else if (k) {
        int now = k;
        v[xx].second -= k;
        pair<char, int> noww = {'W', k};
        v.insert(v.begin() + xx, noww);
      }
    }
    char pre = 'L';
    for (int i = 0, ThxDem = int(v.size()); i < ThxDem; ++i) {
      if (v[i].first == 'L')
        pre = v[i].first;
      else {
        if (pre == 'L')
          ans += 2 * v[i].second - 1;
        else
          ans += 2 * v[i].second;
        pre = v[i].first;
      }
    }
    cout << ans << "\n";
  }
}
