#include <bits/stdc++.h>
using namespace std;
long long int mod1 = 1000000007;
long long int mod2 = 67280421310721;
long long int mod3 = 998244353;
long long int INF = 1e18;
long long int pow1(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
void sieve() {
  long long int n;
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
long long int pow2(long long int a, long long int b, long long int m) {
  a %= m;
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long int setbit(long long int n) { return __builtin_popcount(n); }
void solve() {
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> v;
  int win = 0;
  int W = 0;
  int loss = 0;
  int ans = 0;
  for (char a : s) {
    if (a == 'W') {
      if (loss) {
        v.push_back(loss);
        loss = 0;
      }
      ans++;
      if (W) ans++;
      W = 1;
      win++;
    } else {
      W = 0;
      if (win) loss++;
    }
  }
  if (win == 0) {
    cout << max(2 * k - 1, 0LL) << endl;
  } else if (win + k >= n)
    cout << 2 * n - 1 << endl;
  else {
    sort(v.begin(), v.end());
    ans += 2 * k;
    for (auto x : v) {
      if (x <= k) ans++;
      k -= x;
    }
    cout << ans << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
