#include <bits/stdc++.h>
using namespace std;
vector<long long> gap;
long long n, k, cnt, ccnt;
char seq[100005];
void solve() {
  gap.clear();
  long long lent = 0;
  long long i = 0;
  while (seq[i] == 'L') {
    ++i;
  }
  for (; i < n; ++i) {
    if (seq[i] == 'L') {
      lent++;
    } else {
      if (lent) {
        gap.push_back(lent);
        lent = 0;
      }
    }
  }
  sort(gap.begin(), gap.end());
  long long gaps = gap.size() + 1;
  for (int i = 0; i < (int)gap.size(); ++i) {
    if (k >= gap[i]) {
      k -= gap[i];
      gaps--;
    }
  }
  printf("%lld\n", cnt * 2 - gaps > 0 ? cnt * 2 - gaps : 0);
}
int main() {
  int Case;
  scanf("%d", &Case);
  while (Case--) {
    scanf("%lld %lld", &n, &k);
    getchar();
    ccnt = cnt = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%c", &seq[i]);
      if (seq[i] == 'W') {
        ccnt++;
      }
    }
    cnt = ccnt + k;
    cnt = cnt > n ? n : cnt;
    solve();
  }
  return 0;
}
