#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
int read() {
  char c;
  while ((c = getchar()) < '-')
    ;
  if (c == '-') {
    int x = (c = getchar()) - '0';
    while ((c = getchar()) >= '0') x = x * 10 + c - '0';
    return -x;
  }
  int x = c - '0';
  while ((c = getchar()) >= '0') x = x * 10 + c - '0';
  return x;
}
const int N = 1e5 + 5;
char s[N];
int qw[N], len[N];
int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    int n = read(), k = read();
    scanf("%s", s + 1);
    int cw = 0;
    for (int i = 1; i <= n; ++i)
      if (s[i] == 'W') qw[++cw] = i;
    if (cw == 0 || k >= qw[cw] - qw[1] - (cw - 1)) {
      cw = min(cw + k, n);
      printf("%d\n", cw ? cw * 2 - 1 : 0);
    } else {
      for (int i = 1; i <= cw - 1; ++i) len[i] = qw[i + 1] - qw[i] - 1;
      sort(len + 1, len + cw);
      int s = 0, ans = 0;
      for (int i = 1; i <= cw - 1; ++i)
        if (s + len[i] <= k) {
          s += len[i];
          ++ans;
        }
      printf("%d\n", cw + k * 2 + ans);
    }
  }
}
