#include <bits/stdc++.h>
using namespace std;
long long get_score(string s) {
  long long score = 0;
  bool streak = false;
  for (auto c : s) {
    if (c == 'L')
      streak = false;
    else {
      if (streak)
        score += 2;
      else {
        score++;
        streak = true;
      }
    }
  }
  return score;
}
bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
  return (x.second - x.first) < (y.second - y.first);
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k, init = -1;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<pair<long long, long long>> pos;
    for (long long i = 0; i < n; i++) {
      if (s[i] == 'L') {
        if (init == -1) init = i;
      } else {
        if (init != -1) {
          pos.push_back({init, i - 1});
          init = -1;
        }
      }
    }
    pair<long long, long long> start = {-1, -1}, end = {-1, -1};
    if (pos.size() > 0) start = pos[0];
    if (init != -1) end = {init, n - 1};
    sort(pos.begin(), pos.end(), cmp);
    for (auto x : pos) {
      if (x.first != 0)
        for (long long i = x.first; i <= x.second && k > 0; i++, k--)
          s[i] = 'W';
    }
    if (k && start.first == 0) {
      for (long long i = start.second; i >= start.first && k > 0; i--, k--)
        s[i] = 'W';
    }
    if (k && end.first != -1) {
      for (long long i = end.first; i <= end.second && k > 0; i++, k--)
        s[i] = 'W';
    }
    cout << get_score(s) << endl;
  }
}
