#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > gaps;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    gaps.clear();
    int n, k, first = -1, ff = -1, l = -1;
    string s;
    cin >> n >> k >> s;
    for (int i = 0; i < s.size(); i++) {
      if (ff == -1 && i + 1 < s.size() && s[i] == 'L' && s[i + 1] == 'W')
        ff = i + 1;
      if (i > 0 && s[i] == 'W' && s[i - 1] == 'L' && first != -1)
        gaps.push_back(make_pair(i - first, first));
      if (i + 1 < s.size() && s[i] == 'W' && s[i + 1] == 'L') first = i;
      if (s[i] == 'W') l = i;
    }
    sort(gaps.begin(), gaps.end());
    for (int i = 0; i < gaps.size(); i++) {
      int f = gaps[i].first, second = gaps[i].second;
      for (int j = second + 1; j < f + second; j++) {
        if (k > 0) {
          s[j] = 'W';
          k--;
        } else
          break;
      }
      if (k == 0) break;
    }
    if (k > 0) {
      for (int i = l + 1; i < s.size(); i++) {
        s[i] = 'W';
        k--;
        if (k == 0) break;
      }
      if (k > 0) {
        for (int i = ff - 1; i >= 0; i--) {
          s[i] = 'W';
          k--;
          if (k == 0) break;
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'W') {
        ans++;
        if (i != 0 && s[i - 1] == 'W') ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
