#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'L') {
      int l = 1;
      int index = i;
      while (i + 1 < n && s[i + 1] == 'L') {
        i++;
        l++;
      }
      if (index == 0 || i == n - 1) {
      } else
        pq.push(make_pair(l, index));
    }
  }
  while (!pq.empty() && k > 0) {
    pair<int, int> p = pq.top();
    pq.pop();
    int index = p.second;
    for (int i = index; i < n && k > 0; i++) {
      if (s[i] == 'W') break;
      s[i] = 'W';
      k--;
    }
  }
  if (k > 0) {
    int index = n - 1;
    for (; index >= 0 && k > 0; index--) {
      if (s[index] == 'W') break;
    }
    index++;
    for (int i = index; i < n && k > 0; i++) {
      if (s[i] == 'L') {
        s[i] = 'W';
        k--;
      }
    }
    index = 0;
    for (; index < n && k > 0; index++) {
      if (s[index] == 'W') break;
    }
    for (int i = index; i >= 0 && k > 0; i--) {
      if (s[i] == 'L') {
        k--;
        s[i] = 'W';
      }
    }
  }
  int score = s[0] == 'W';
  for (int i = 1; i < n; i++) {
    if (s[i] == 'W' && s[i - 1] == 'W')
      score += 2;
    else if (s[i] == 'W')
      score++;
  }
  cout << score << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
