#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  ;
  string s;
  cin >> s;
  long long int nl = 0, nw = 0;
  vector<long long int> g;
  long long int gl = 0;
  bool ok = false;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == 'W')
      nw++;
    else {
      nl++;
    }
    if (s[i] == 'W') {
      if (gl != 0) g.push_back(gl);
      gl = 0;
      ok = true;
    } else {
      if (ok) gl++;
    }
  }
  if (nl <= k) {
    cout << 1 + ((n - 1) * 2) << "\n";
    return;
  }
  if (nw == 0) {
    if (k == 0)
      cout << 0 << "\n";
    else
      cout << 1 + ((k - 1) * 2) << "\n";
    return;
  }
  sort((g).begin(), (g).end());
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    if (i == 0) {
      if (s[i] == 'W') ans++;
      continue;
    }
    if (s[i] == 'W') {
      ans++;
      if (s[i - 1] == 'W') ans++;
    }
  }
  for (auto e : g) {
    if (e <= k) {
      ans += 1 + (e * 2);
      k -= e;
    } else {
      break;
    }
  }
  ans += k * 2;
  cout << ans;
  cout << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t-- > 0) {
    solve();
  }
  return 0;
}
