#include <bits/stdc++.h>
using namespace std;
const int MAX = 200000;
const int MOD = 1000000007;
const int OO = 0x3f3f3f3f;
const double EPS = 1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int32_t main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    string s;
    cin >> n >> k >> s;
    int l = 0, r = n - 1;
    while (l < n and s[l] == 'L') l++;
    while (r >= 0 and s[r] == 'L') r--;
    vector<pair<int, int> > arr;
    while (l <= r) {
      while (l <= r and s[l] != 'L') l++;
      int L = l;
      while (l <= r and s[l] == 'L') l++;
      int R = l - 1;
      if (L <= R) arr.push_back({L, R});
    }
    sort(arr.begin(), arr.end(), [](pair<int, int> a, pair<int, int> b) {
      return a.second - a.first < b.second - b.first;
    });
    for (int i = 0; i < arr.size(); i++) {
      int a = arr[i].first;
      int b = arr[i].second;
      if (b - a + 1 > k) continue;
      for (int j = a; j <= b; j++) s[j] = 'W';
      k -= (b - a + 1);
    }
    int w = 0;
    for (int i = 0; i < n; i++)
      if (s[i] == 'W') w = i, i = n;
    for (int j = w; j < n and k > 0; j++)
      if (s[j] == 'L') s[j] = 'W', k--;
    for (int j = w; j >= 0 and k > 0; j--)
      if (s[j] == 'L') s[j] = 'W', k--;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] != 'W') continue;
      if (!i)
        ans++;
      else if (s[i - 1] == 'W')
        ans += 2;
      else
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
