#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
int n, t, k, res;
char a[N];
priority_queue<int, vector<int>, greater<int> > pq;
void inp() {
  scanf("%d %d", &n, &k);
  scanf("%s", a + 1);
}
void proc() {
  res = 0;
  int cnt = 0, dem1 = 0, dem2 = 0;
  for (int i = (1), _y = (n); i <= _y; ++i) {
    if (a[i] != 'L') {
      if (!res)
        dem1 = cnt;
      else {
        if (cnt) pq.push(cnt);
      }
      cnt = 0;
      ++res;
      if (a[i - 1] == 'W') ++res;
    } else
      ++cnt;
  }
  if (a[n] == 'L') dem2 = cnt;
  while (!pq.empty() && k) {
    if (pq.top() > k)
      res += 2 * k, k = 0;
    else
      k -= pq.top(), res += 2 * pq.top() + 1;
    pq.pop();
  }
  while (!pq.empty()) pq.pop();
  if (dem1 > dem2) swap(dem1, dem2);
  if (dem2 == n) {
    res = (min(dem2, k) - 1) * 2 + 1;
    res = max(res, 0);
    printf("%d\n", res);
    return;
  }
  if (dem2) {
    if (k >= dem2) {
      k -= dem2 - 1, res += 2 * (dem2 - 1);
      dem2 = 1;
    } else {
      res += (k - 1) * 2;
      dem2 -= k - 1, k = 1;
    }
    if (dem1) {
      if (k >= dem1) {
        k -= dem1 - 1, res += 2 * (dem1 - 1);
        dem1 = 1;
      } else {
        res += (k - 1) * 2;
        dem1 -= k - 1, k = 1;
      }
    }
  }
  if (dem1 && k) --k, res += 2;
  if (dem2 && k) --k, res += 2;
  printf("%d\n", res);
}
int main() {
  scanf("%d", &t);
  for (int i = (1), _y = (t); i <= _y; ++i) {
    inp();
    proc();
  }
}
