#include <bits/stdc++.h>
using namespace std;
const int N = 100007;
int T, n, k;
char c[N];
int f[N][3], z[N], cnt, cntw, cntz;
int main() {
  scanf("%d", &T);
  while (T--) {
    memset(f, 0, sizeof(f));
    memset(z, 0, sizeof(z));
    cnt = 0, cntw = 0, cntz = 0;
    scanf("%d %d", &n, &k);
    cin >> c;
    for (int i = 0; i <= n - 1; i++) {
      if (c[i] == 'W' && !i) f[++cnt][1] = i;
      if (c[i] == 'W' && c[i - 1] == 'L') f[++cnt][1] = i;
      if (c[i] == 'W' && c[i + 1] == 'L') f[cnt][2] = i;
      if (c[i] == 'W') cntw++;
    }
    if (!cnt) {
      if (k == 0) {
        printf("0\n");
        continue;
      }
      if (k <= n) {
        printf("%d\n", k * 2 - 1);
        continue;
      }
      if (k > n) {
        printf("%d\n", n * 2 - 1);
        continue;
      }
    }
    if (cntw + k >= n) {
      printf("%d\n", n * 2 - 1);
      continue;
    }
    for (int i = 2; i <= cnt; i++) z[i - 1] = f[i][1] - f[i - 1][2] - 1;
    sort(z + 1, z + cnt);
    for (int i = 1; i <= cnt - 1; i++) cntz += z[i];
    if (k >= cntz) {
      printf("%d\n", (cntw + k) * 2 - 1);
      continue;
    }
    int ans = cntw * 2 - cnt;
    for (int i = 1; i <= cnt - 1; i++)
      if (k >= z[i]) {
        k -= z[i];
        ans += (z[i] * 2 + 1);
      } else {
        ans += (k * 2);
        break;
      }
    printf("%d\n", ans);
  }
}
