#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int cur = 0;
  vector<int> v;
  int c = s[0] == 'L';
  int ans = s[0] == 'W';
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == 'W') {
      ans += 1 + (s[i - 1] == 'W');
    } else
      c++;
  }
  if (c == n) {
    cout << max(0, k * 2 - 1) << endl;
    return;
  }
  for (auto i : s) {
    if (i == 'L')
      cur++;
    else {
      v.push_back(cur);
      cur = 0;
    }
  }
  if (v.size()) {
    cur += v[0];
    swap(v[0], v[v.size() - 1]);
    v.pop_back();
  }
  sort((v).begin(), (v).end());
  int ind = 0;
  int d = 0;
  while (ind < v.size() && d < k) {
    if (v[ind] == 0) {
      ind++;
      continue;
    } else {
      if (v[ind] == 1)
        ans += 3;
      else
        ans += 2;
      v[ind]--;
      d++;
    }
  }
  ans += (min(k - d, cur) * 2);
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
