#include <bits/stdc++.h>
using namespace std;
namespace IO {
inline long long read() {
  long long o = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    o = o * 10 + c - '0';
    c = getchar();
  }
  return o * f;
}
}  // namespace IO
using namespace IO;
const int N = 1e5 + 7, M = 1e6 + 7, INF = 0x3f3f3f3f, Mod = 1e9 + 7;
char a[N];
int b[N], tot;
int t, n, k;
vector<int> pos;
int main() {
  cin >> t;
  while (t--) {
    tot = 0;
    cin >> n >> k;
    cin >> a;
    int cnt = 0;
    bool f = 0;
    for (int i = 0, s = 0; i < n; i++) {
      if (a[i] == 'W') {
        f = 1;
        cnt++;
      }
      if (a[i] == 'L' && f) {
        s++;
      } else {
        if (s > 0) {
          b[++tot] = s;
          s = 0;
        }
      }
    }
    if (cnt + k >= n) {
      cout << (2 * n) - 1 << endl;
      continue;
    }
    sort(b + 1, b + 1 + tot);
    int t = 0, first = 0;
    for (int i = 1; i <= tot; i++) {
      t += b[i];
      if (t > k) {
        first = tot - i + 2;
        break;
      }
    }
    if (t <= k && (cnt || k)) {
      first = 1;
    }
    cout << (cnt + k) * 2 - first << endl;
  }
  return 0;
}
