#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int t;
  for (cin >> t; t--;) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int rem = k;
    vector<pair<int, int>> dist;
    int prev = -1;
    for (int i = 0; i < n; i++) {
      if (s.at(i) == 'W') {
        if (prev != -1) {
          pair<int, int> ins;
          ins.first = i - prev - 1;
          ins.second = prev + 1;
          if (ins.first > 0) {
            dist.push_back(ins);
          }
        }
        prev = i;
      }
    }
    sort(dist.begin(), dist.end());
    for (pair<int, int> &v : dist) {
      if (rem - v.first >= 0) {
        rem -= v.first;
        for (int i = v.second; i < v.second + v.first; i++) {
          assert(i < n);
          s.at(i) = 'W';
        }
      }
    }
    for (int i = 1; i < n; i++) {
      if (rem > 0 and s.at(i) == 'L' and s.at(i - 1) == 'W') {
        s.at(i) = 'W';
        rem--;
      }
    }
    for (int i = n - 2; i >= 0; i--) {
      if (rem > 0 and s.at(i) == 'L' and s.at(i + 1) == 'W') {
        rem--;
        s.at(i) = 'W';
      }
    }
    for (int i = 0; i < n; i++) {
      if (rem > 0 and s.at(i) == 'L') {
        s.at(i) = 'W';
        rem--;
      }
    }
    int score = 0;
    for (int i = 0; i < n; i++) {
      if (s.at(i) == 'W') {
        score++;
        if (i > 0 and s.at(i - 1) == 'W') {
          score++;
        }
      }
    }
    cout << score << endl;
  }
  return 0;
}
