#include <bits/stdc++.h>
using namespace std;
int read() {
  char c;
  int num, f = 1;
  while (c = getchar(), !isdigit(c))
    if (c == '-') f = -1;
  num = c - '0';
  while (c = getchar(), isdigit(c)) num = num * 10 + c - '0';
  return num * f;
}
int n, k, cnt, a[100009], tot, ans;
char c[100009];
void work() {
  n = read();
  k = read();
  cnt = 0;
  tot = 0;
  ans = 0;
  scanf("%s", c + 1);
  for (int i = 1; i <= n; i++) cnt += c[i] == 'L';
  for (int i = 1; i <= n; i++) {
    if (c[i] == 'W') {
      if (i == 1 || c[i - 1] == 'L')
        ans++;
      else
        ans += 2;
    }
  }
  if (k == 0) {
    printf("%d\n", ans);
    return;
  }
  if (k > cnt) {
    printf("%d\n", 2 * n - 1);
    return;
  }
  if (cnt == n) {
    printf("%d\n", 2 * k - 1);
    return;
  }
  int now = 1;
  cnt = 0;
  while (c[now] != 'W') now++;
  for (; now <= n; now++) {
    if (c[now] == 'W') {
      if (cnt > 0) a[++tot] = cnt;
      cnt = 0;
    } else {
      cnt++;
    }
  }
  sort(a + 1, a + 1 + tot);
  for (int i = 1; i <= tot; i++) {
    if (k < a[i]) break;
    k -= a[i];
    ans += a[i] * 2 + 1;
  }
  if (k) ans += 2 * k;
  printf("%d\n", ans);
}
int main() {
  int Case = read();
  while (Case--) work();
  return 0;
}
