#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 100010;
char s[N];
int n, k;
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie(0);
  int T = 1;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    cin >> s + 1;
    priority_queue<int, vector<int>, greater<int>> q1, q2, q3;
    priority_queue<int> p1, p2;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i] == 'L')
        cnt++;
      else {
        if (!cnt) continue;
        if (i > cnt + 1 && s[i - cnt - 1] == 'W' && i <= n && s[i] == 'W')
          q1.push(cnt);
        else if (i > cnt + 1 && s[i - cnt - 1] == 'W' || i <= n && s[i] == 'W')
          q2.push(cnt);
        else
          q3.push(cnt);
        cnt = 0;
      }
    }
    if (cnt) {
      if (n > cnt && s[n - cnt] == 'W')
        q2.push(cnt);
      else
        q3.push(cnt);
    }
    int res = 0;
    while (k && q1.size()) {
      auto v = q1.top();
      q1.pop();
      if (k >= v)
        res += 2 * v + 1, k -= v;
      else
        p1.push(v);
    }
    while (k && q2.size()) {
      auto v = q2.top();
      q2.pop();
      if (k >= v)
        res += 2 * v, k -= v;
      else
        p2.push(v);
    }
    while (k && (p1.size() || p2.size())) {
      res += 2 * k;
      k = 0;
    }
    if (k && q3.size()) {
      auto v = q3.top();
      res = 2 * min(k, v) - 1;
    }
    for (int i = 1; i <= n; i++) {
      if (s[i] == 'W') {
        if (i > 1 && s[i - 1] == 'W')
          res += 2;
        else
          res++;
      }
    }
    cout << res << '\n';
  }
  return 0;
}
