#include <bits/stdc++.h>
using namespace std;
class cmp {
  int n;

 public:
  cmp(int p) : n(p) {}
  bool operator()(pair<int, int> &a, pair<int, int> &b) {
    int x = a.second - a.first + 1;
    int y = b.second - b.first + 1;
    if (a.first == 0) return false;
    if (b.first == 0) return true;
    if (a.second == n) return false;
    if (b.second == n) return true;
    return x <= y;
  }
};
bool comp(pair<int, int> &a, pair<int, int> &b) {
  return a.second - a.first < b.second - b.first;
}
int get(string &w) {
  int cnt = 0;
  for (int i = 0; i < (int)w.size(); i++) {
    if (w[i] == 'W') {
      if (i != 0 && w[i - 1] != 'L')
        cnt += 2;
      else
        cnt++;
    }
  }
  return cnt;
}
int solve(string &s, int k) {
  int n = s.size();
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'L') cnt++;
  }
  if (k >= cnt) {
    return 2 * (n - 1) + 1;
  }
  vector<pair<int, int>> v;
  int ind = 0;
  while (ind < n && s[ind] == 'L') ind++;
  int l = ind - 1;
  int m = n - 1;
  while (m >= 0 && s[m] == 'L') {
    m--;
  }
  while (ind <= m) {
    if (s[ind] == 'W')
      ind++;
    else {
      int a = ind;
      int b = ind;
      while (b < n && s[b] == 'L') b++;
      v.push_back({a, b - 1});
      ind = b;
    }
  }
  sort(v.begin(), v.end(), comp);
  for (int i = 0; i < (int)v.size() && k > 0; i++) {
    int p = v[i].first;
    int q = v[i].second;
    if (p == 0) {
      for (; q >= p && k > 0; q--) {
        s[q] = 'W';
        k--;
      }
    } else {
      for (; p <= v[i].second && k > 0; p++) {
        s[p] = 'W';
        k--;
      }
    }
  }
  m++;
  while (m < n && k > 0) {
    s[m] = 'W';
    m++;
    k--;
  }
  while (l >= 0 && k > 0) {
    s[l] = 'W';
    l--;
    k--;
  }
  return get(s);
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    cout << solve(s, k) << endl;
  }
}
