#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
namespace number_theory {
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  if (y == 0) return x;
  return gcd(y, x % y);
}
bool isprime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i += 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
bool prime[15000105];
void sieve(long long n) {
  for (long long i = 0; i <= n; i++) prime[i] = 1;
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  prime[1] = prime[0] = 0;
}
vector<long long> primelist;
bool __primes_generated__ = 0;
void genprimes(long long n) {
  __primes_generated__ = 1;
  sieve(n + 1);
  for (long long i = 2; i <= n; i++)
    if (prime[i]) primelist.push_back(i);
}
vector<long long> factors(long long n) {
  if (!__primes_generated__) {
    cerr << "Caint genprimes you dope" << endl;
    exit(1);
  }
  vector<long long> facs;
  for (long long i = 0;
       primelist[i] * primelist[i] <= n && i < primelist.size(); i++) {
    if (n % primelist[i] == 0) {
      while (n % primelist[i] == 0) {
        n /= primelist[i];
        facs.push_back(primelist[i]);
      }
    }
  }
  if (n > 1) {
    facs.push_back(n);
  }
  sort(facs.begin(), facs.end());
  return facs;
}
vector<long long> getdivs(long long n) {
  vector<long long> divs;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      divs.push_back(i);
      divs.push_back(n / i);
    }
  }
  {
    sort(divs.begin(), divs.end());
    divs.erase(unique(divs.begin(), divs.end()), divs.end());
  };
  return divs;
}
}  // namespace number_theory
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long win = 0, loss = 0, winning_streak_cnt = 0;
  vector<long long> lossing_streak;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'W') {
      win++;
      if (i == 0 or s[i - 1] == 'L') winning_streak_cnt++;
    } else {
      loss++;
      if (i == 0 or s[i - 1] == 'W') lossing_streak.push_back(0);
      lossing_streak.back()++;
    }
  }
  if (k >= loss) {
    cout << 2 * n - 1 << "\n";
    return;
  }
  if (win == 0) {
    if (k == 0)
      cout << 0;
    else
      cout << 2 * k - 1;
    cout << "\n";
    return;
  }
  win += k;
  if (s[0] == 'L') lossing_streak[0] = 1e8;
  if (s[n - 1] == 'L') lossing_streak.back() = 1e8;
  sort(lossing_streak.begin(), lossing_streak.end());
  for (long long ls : lossing_streak) {
    if (ls > k) break;
    k -= ls;
    winning_streak_cnt--;
  }
  cout << 2 * win - winning_streak_cnt << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
