#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long expo_pow(long long x, long long y) {
  if (y == 0) return 1;
  y = y % (mod - 1);
  x %= mod;
  if (y == 0) y = mod - 1;
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return res;
}
long long add() { return 0; }
template <typename T, typename... Types>
T add(T var1, Types... var2) {
  return (((((long long)(var1)) % mod + (long long)(add(var2...))) % mod) +
          mod) %
         mod;
}
long long mul() { return 1; }
template <typename T, typename... Types>
T mul(T var1, Types... var2) {
  return (((long long)(var1)) % mod * (long long)(mul(var2...))) % mod;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  string second;
  cin >> second;
  long long cnt = 0;
  for (auto u : second) cnt += (u == 'W');
  if (cnt == 0) {
    long long ans = 2 * k - 1;
    cout << max(0LL, ans) << "\n";
    return;
  }
  vector<long long> idx;
  long long i = 0;
  while (i < n and second[i] == 'L') i++;
  while (i < n) {
    long long j = i;
    while (j < n and second[j] == 'W') j++;
    long long tmp = j;
    while (j < n and second[j] == 'L') j++;
    if (j < n) idx.push_back(j - tmp);
    i = j;
  }
  if (cnt + k >= n) {
    cout << 2 * n - 1 << "\n";
    return;
  }
  long long ans = cnt;
  for (long long i = 1; i < n; ++i) {
    if (second[i] == 'W' and second[i - 1] == 'W') ans++;
  }
  sort(idx.begin(), idx.end());
  for (auto u : idx) {
    if (k >= u) {
      ans += 2 * u;
      ans++;
      k -= u;
    } else if (k != 0) {
      ans += 2 * k;
      k = 0;
    }
  }
  if (k) ans += 2 * k;
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  cin >> test;
  long long i = 1;
  while (test--) {
    solve();
  }
}
