#include <bits/stdc++.h>
using namespace std;
const int NN = 100100;
char s[NN];
int n, k;
vector<int> rec[NN];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &k);
    scanf("%s", s + 1);
    int numw = 0;
    for (int i = 1; i <= n; i++) {
      rec[i].clear();
      numw += (s[i] == 'W');
    }
    if (numw == 0) {
      printf("%d\n", max(0, 2 * k - 1));
      continue;
    }
    int last = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i] == 'L' && (s[i - 1] == 'W')) {
        last = i;
      }
      if (s[i] == 'L' && (s[i + 1] == 'W') && last) {
        rec[i - last + 1].push_back(last);
      }
    }
    for (int i = 1; i <= n; i++) {
      if (k == 0) break;
      int up = rec[i].size();
      for (int j = 0; j < up; j++) {
        if (k == 0) break;
        int ll = rec[i][j];
        for (int p = 0; p < i; p++) {
          if (k == 0) break;
          s[ll + p] = 'W';
          k--;
        }
      }
    }
    if (k) {
      for (int i = 1; i <= n; i++) {
        if (s[i] == 'L' && s[i - 1] == 'W') {
          s[i] = 'W';
          k--;
        }
        if (k == 0) break;
      }
    }
    if (k) {
      for (int i = n; i >= 1; i--) {
        if (s[i] == 'L' && s[i + 1] == 'W') {
          s[i] = 'W';
          k--;
        }
        if (k == 0) break;
      }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i] == 'W') {
        ans += 1;
        ans += (s[i - 1] == 'W');
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
