#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void solve() {
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<long long int> gap;
  long long int front = 0;
  long long int i = 0;
  while (i < n && s[i] == 'L') {
    front++;
    i++;
  }
  if (i == n) {
    cout << max(0LL, 2 * min(n, k) - 1) << "\n";
    return;
  }
  long long int cnt = 0;
  long long int ans = 0;
  long long int loss = 0;
  long long int win = 0;
  for (; i < n; i++) {
    if (s[i] == 'L') {
      loss++;
      win = 0;
    } else {
      if (win == 0) {
        ans += 1;
      } else {
        ans += 2;
      }
      if (loss > 0) {
        gap.push_back(loss);
        loss = 0;
      }
      win++;
    }
  }
  sort(gap.begin(), gap.end());
  for (long long int i = 0; i < gap.size(); i++) {
    if (k < gap[i]) {
      ans += 2 * k;
      k = 0;
    } else {
      ans += (2 * gap[i] + 1);
      k -= gap[i];
    }
    if (k == 0) {
      break;
    }
  }
  if (k > 0) {
    ans = min(2 * n - 1, ans + (k * 2));
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
