#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1E5 + 100;
int bet[MAXN];
int n, k, indx, wcnt;
string s;
void input();
void solve();
void makeBet();
void make0();
int main() {
  int T;
  cin >> T;
  while (T--) {
    input();
    make0();
    makeBet();
    solve();
  }
}
void make0() {
  for (int i = 0; i < n; i++) bet[i] = 0;
}
void solve() {
  if (wcnt + k >= n) {
    cout << 2 * n - 1 << endl;
    return;
  }
  if (k == 0) {
    cout << wcnt * 2 - indx << endl;
    return;
  }
  if (wcnt == 0) {
    cout << 2 * k - 1 << endl;
    return;
  }
  wcnt += k;
  sort(bet + 1, bet + indx);
  int component = indx;
  for (int i = 1; i < indx; i++) {
    if (k >= bet[i]) {
      k -= bet[i];
      component--;
    } else
      break;
  }
  cout << 1ll * wcnt * 2 - component << endl;
}
void makeBet() {
  int cntl = 0;
  s = "L" + s;
  indx = 0, wcnt = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'W') wcnt++;
    if (s[i] == 'W' && s[i - 1] != 'W') indx++;
    if (s[i] == 'L') bet[indx]++;
  }
}
void input() {
  cin >> n >> k;
  cin >> s;
}
