#include <bits/stdc++.h>
using namespace std;
long long a, b, c[300200], d[300200], n, m, k, r, l, t, q;
long long ans, ans2, ans3, sum, sum2, mx = -1e18, mn = 1e18;
string second, s1, ss;
bool ch, ch2, ch3, ch4;
int was[200200];
set<int> st;
vector<int> vv;
pair<int, int> p[300200];
vector<pair<int, int> > v[200200];
map<string, int> ma;
double bo[200][200], g;
const int inf = 1e9, mod = 1e9 + 7, N = 1e6 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> k;
    cin >> second;
    ans = 0;
    q = -1;
    for (int i = 0; i < second.size(); i++) {
      if (second[i] == 'W') {
        if (q != -1) {
          v[i - q - 1].push_back(make_pair(q, i));
          st.insert(i - q - 1);
          if (q + 1 == i) {
            ans += 2;
          } else
            ans++;
        } else
          ans++;
        q = i;
      }
    }
    if (q != -1) q = 0;
    for (int i = 1; i <= k; i++) {
      for (int j = 0; j < v[i].size(); j++) {
        if (i <= k) {
          for (int l = v[i][j].first + 1; l < v[i][j].second; l++) {
            second[l] = 'W';
          }
          k -= i;
          ans += i * 2 + 1;
        } else
          break;
      }
    }
    for (int i = 0; i < n; i++) {
      if (second[i] == 'L') {
        if (k >= 1) {
          if (q != -1)
            ans += 2;
          else
            ans++, q = 1;
          k--;
        } else
          break;
      }
    }
    cout << ans << '\n';
    for (auto it : st) {
      v[it].clear();
    }
  }
  return 0;
}
