#include <bits/stdc++.h>
using namespace std;
int main() {
  int T, N, K;
  string s;
  for (cin >> T; T; T--) {
    cin >> N >> K;
    cin >> s;
    int start = 0, end = N;
    int ans = -1;
    vector<int> runLens(1, 0);
    while (start < N && s[start] == 'L') start++;
    while (end > 0 && s[end - 1] == 'L') end--;
    if (end == 0) {
      cout << max(K * 2 - 1, 0) << endl;
      continue;
    }
    for (int i = start; i < end; i++)
      if (s[i] == 'L')
        runLens[runLens.size() - 1]++;
      else if (runLens.back()) {
        runLens.push_back(0);
        ans++;
      } else
        ans += 2;
    runLens.pop_back();
    sort(runLens.begin(), runLens.end());
    for (int i = 0; i < runLens.size(); i++)
      if (K >= runLens[i]) {
        K -= runLens[i];
        ans += 2 * runLens[i] + 1;
      } else {
        ans += K * 2;
        K = 0;
      }
    ans += min(K, start + (N - end)) * 2;
    cout << ans << endl;
  }
}
