#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<pair<int, pair<int, int>>> v;
    int b = -1, mn = 0, mx = n - 1;
    bool ok = (s[0] == 'W');
    for (int i = 0; i < n; i++) {
      if (s[i] == 'W' && b == -1) {
        ok = 1;
        b = i;
        mn = i;
      } else if (s[i] == 'W') {
        if (ok) {
          b = i;
          continue;
        }
        v.push_back(make_pair(i - b, make_pair(b, i)));
        b = i;
        ok = 1;
      } else
        ok = 0;
    }
    mx = b;
    sort(v.begin(), v.end());
    if (v.size() == 0) {
      for (int i = mn; i >= 0; i--) {
        if (!k) break;
        if (s[i] == 'L') {
          s[i] = 'W';
          k--;
        }
      }
      for (int i = 0; i < n; i++) {
        if (!k) break;
        if (s[i] == 'L') {
          s[i] = 'W';
          k--;
        }
      }
    } else {
      for (int i = 0; i < (int)v.size(); i++) {
        for (int j = v[i].second.first + 1; j < v[i].second.second; j++) {
          if (!k) break;
          if (s[j] == 'L') {
            k--;
            s[j] = 'W';
          }
        }
      }
      if (k) {
        for (int i = mn; i >= 0; i--) {
          if (!k) break;
          if (s[i] == 'L') {
            s[i] = 'W';
            k--;
          }
        }
        for (int i = 0; i < n; i++) {
          if (!k) break;
          if (s[i] == 'L') {
            s[i] = 'W';
            k--;
          }
        }
      }
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'W') {
        if (!i || s[i - 1] != s[i])
          ans++;
        else
          ans += 2;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
