#include <bits/stdc++.h>
using namespace std;
const int sz = 1e5 + 9, infP = INT_MAX, infN = INT_MIN, mod = 1e9 + 7,
          eps = 1e-9;
void ini() { return; }
void solve() {
  long long int n, m, k, l, r, ans = 0, cntL = 0;
  string s;
  cin >> n >> k >> s;
  int ind[n];
  m = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'L') {
      ind[i] = m;
      m = i;
    } else {
      ind[i] = m;
    }
  }
  m = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'W' && m == 0) {
      m = 1;
      ans += 1;
      continue;
    }
    if (s[i] == 'W' && m == 1) {
      ans += 2;
      continue;
    }
    if (s[i] == 'L') cntL++;
    m = 0;
  }
  if (k == 0) {
    cout << ans << "\n";
    return;
  }
  if (cntL == n) {
    if (k >= n) {
      ans = n * 2;
      ans -= 1;
    } else {
      ans = k * 2;
      ans -= 1;
    }
    cout << ans << "\n";
    return;
  }
  int start = 0, last = -1, stop = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'W') {
      break;
    }
    last = i;
    start++;
  }
  vector<int> lst;
  for (int i = last + 1; i < n; i++) {
    if (s[i] == 'W') {
      if (i - 1 != last) {
        lst.push_back(i - last - 1);
      }
      last = i;
    }
  }
  for (int i = last + 1; i < n; i++) {
    stop++;
  }
  sort(lst.begin(), lst.end());
  ;
  for (int i = 0; i < lst.size(); i++) {
    if (lst[i] <= k) {
      ans += lst[i] * 2;
      ans++;
      k -= lst[i];
    } else {
      ans += k * 2;
      k = 0;
      break;
    }
  }
  if (k == 0) {
    cout << ans << "\n";
    return;
  }
  if (stop >= k) {
    ans += k * 2;
    k = 0;
  } else {
    ans += stop * 2;
    k = k - stop;
  }
  if (k == 0) {
    cout << ans << "\n";
    return;
  }
  if (start >= k) {
    ans += k * 2;
    k = 0;
  } else {
    ans += start * 2;
    k = k - stop;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  cin >> t;
  while (t--) solve();
}
