#include <bits/stdc++.h>
using namespace std;
double start_moment = 0;
double get_runtime() { return 1.0 * clock() / CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime() { cout << fixed << setprecision(5) << get_runtime() << '\n'; }
template <class T>
void read(vector<T> &a, long long n) {
  T x;
  a.clear();
  for (long long i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
}
template <class T>
void write(vector<T> &a) {
  for (T x : a) cout << x << ' ';
  cout << '\n';
}
int n, k;
string second;
int main() {
  ios_base::sync_with_stdio(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    cin >> second;
    int p1 = 0;
    int p2 = n - 1;
    while (p1 < second.size() && second[p1] == 'L') p1++;
    while (p2 >= 0 && second[p2] == 'L') p2--;
    if (p1 == second.size()) {
      for (int i = 0; i < k; i++) {
        second[i] = 'W';
      }
      int res = 0;
      for (int i = 0; i < n; i++) {
        if (second[i] == 'W') {
          if (i && second[i - 1] == 'W') {
            res += 2;
          } else {
            res += 1;
          }
        }
      }
      cout << res << '\n';
      continue;
    }
    int cur = 0;
    int pos = n;
    vector<pair<int, int> > v;
    for (int i = p1; i <= p2; i++) {
      if (second[i] == 'L') {
        cur++;
        pos = min(pos, i);
      } else {
        v.push_back(make_pair(cur, pos));
        cur = 0;
        pos = n;
      }
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
      if (k > 0) {
        int can = min(k, v[i].first);
        for (int j = 0; j < can; j++) {
          second[v[i].second + j] = 'W';
        }
        k -= can;
      }
    }
    for (int i = p2; i < n; i++) {
      if (k && second[i] == 'L') {
        k--;
        second[i] = 'W';
      }
    }
    for (int i = p1; i >= 0; i--) {
      if (k && second[i] == 'L') {
        k--;
        second[i] = 'W';
      }
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
      if (second[i] == 'W') {
        if (i && second[i - 1] == 'W') {
          res += 2;
        } else {
          res += 1;
        }
      }
    }
    cout << res << '\n';
  }
}
