#include <bits/stdc++.h>
using namespace std;
char a[100000 + 200];
int lose[100000 + 100];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int len, k;
    memset(lose, 0, sizeof(lose));
    cin >> len >> k;
    scanf("%s", a);
    int ans = 0, L = 0, c = 0, Lnum = 0;
    bool flag = false;
    for (int i = 0; i < len; i++) {
      if (a[i] == 'W') {
        flag = true;
        if (L != 0) {
          lose[++c] = L;
          L = 0;
        }
        if (a[i - 1] != 'W')
          ans += 1;
        else
          ans += 2;
      } else if (a[i] == 'L') {
        Lnum++;
        if (flag) L++;
      }
    }
    if (L) {
      lose[++c] = L;
      L = 0;
    }
    if (Lnum == len) {
      printf("%d\n", max(0, min(k, len) * 2 - 1));
      continue;
    }
    if (a[len - 1] == 'L') {
      c--;
    }
    sort(lose + 1, lose + c + 1);
    int ori = 1;
    while (k && lose[ori] != 0) {
      if (k >= lose[ori] && ori <= c) {
        k -= lose[ori];
        ans += lose[ori] * 2 + 1;
        Lnum -= lose[ori];
        ori++;
      } else {
        break;
      }
    }
    if (k > 0 && Lnum > 0) {
      int temp = min(k, Lnum);
      ans += temp * 2;
    }
    printf("%d\n", ans);
  }
  return 0;
}
