#include <bits/stdc++.h>
using namespace std;
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (auto& v : vec) is >> v;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[ ";
  for (int i = 0; i < v.size(); ++i) {
    os << v[i];
    if (i != v.size() - 1) os << ", ";
  }
  os << " ]\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "[ ";
  for (auto it : v) {
    os << it;
    if (it != *v.rbegin()) os << ", ";
  }
  os << " ]\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& v) {
  os << "[ ";
  for (auto it : v) os << it << ", ";
  os << " ]\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  os << "{ ";
  for (auto it : v) os << it.first << " : " << it.second << ", ";
  os << " }\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  os << "(";
  os << v.first << ", " << v.second << ")";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, priority_queue<T> p) {
  os << "[ ";
  while (!p.empty()) {
    os << p.top() << " ,";
    p.pop();
  }
  os << " ]\n";
  return os;
}
inline long long pmod(long long i, long long n) { return (i % n + n) % n; }
const long long INF = 1e18;
const long long mod = 1e9 + 7;
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long fw = -1, lw = -2;
  for (long long(i) = (0); (i) <= (n - 1); ++(i))
    if (s[i] == 'W') {
      fw = i;
      break;
    }
  for (long long(i) = (n - 1); (i) >= (0); --(i))
    if (s[i] == 'W') {
      lw = i;
      break;
    }
  vector<pair<long long, long long>> cnt;
  long long cur = 0, pos;
  for (long long(i) = (fw); (i) <= (lw); ++(i)) {
    if (s[i] == 'W') continue;
    if (!cur) pos = i;
    ++cur;
    if (i + 1 <= lw && s[i + 1] == 'L') continue;
    cnt.push_back({cur, pos});
    cur = 0;
  }
  sort((cnt).begin(), (cnt).end());
  for (auto&(e) : (cnt))
    for (long long(i) = (e.second); (i) <= (e.first + e.second - 1); ++(i))
      if (k) {
        --k;
        s[i] = 'W';
      }
  if (fw != -1)
    for (long long(i) = (fw - 1); (i) >= (0); --(i))
      if (k) {
        s[i] = 'W';
        --k;
      }
  if (lw != -2)
    for (long long(i) = (lw + 1); (i) <= (n - 1); ++(i))
      if (k) {
        s[i] = 'W';
        --k;
      }
  for (long long(i) = (0); (i) <= (n - 1); ++(i))
    if (s[i] == 'L' && k) {
      s[i] = 'W';
      --k;
    }
  long long ans = (s[0] == 'W');
  for (long long(i) = (1); (i) <= (n - 1); ++(i))
    if (s[i] == 'W')
      if (s[i - 1] == 'W')
        ans += 2;
      else
        ++ans;
  cout << ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  for (int t1 = 1; t1 <= t; ++t1) {
    solve();
    cout << '\n';
  }
}
