#include <bits/stdc++.h>
using namespace std;
const long long M = 1e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int beg = 0;
    int end = 0;
    int mv = 0;
    while (mv < n && s[mv] == 'L') {
      mv++;
      beg++;
    }
    mv = n - 1;
    while (mv >= 0 && s[mv] == 'L') {
      mv--;
      end++;
    }
    vector<pair<int, pair<int, int> > > len;
    int i = beg;
    while (i < n - end) {
      if (s[i] == 'W') {
        i++;
        continue;
      }
      int shuru = i;
      while (i < n - end && s[i] == 'L') i++;
      int khatm = i - 1;
      len.push_back(make_pair(khatm - shuru + 1, make_pair(shuru, khatm)));
    }
    sort(len.begin(), len.end());
    if (beg >= end) {
      len.push_back(make_pair(beg, make_pair(0, beg - 1)));
      len.push_back(make_pair(end, make_pair(n - end, n - 1)));
    } else {
      len.push_back(make_pair(end, make_pair(n - end, n - 1)));
      len.push_back(make_pair(beg, make_pair(0, beg - 1)));
    }
    for (i = 0; i < len.size(); i++) {
      if (k >= len[i].first) {
        k -= len[i].first;
        if (len[i].second.first != 0) {
          for (int j = len[i].second.first; j <= len[i].second.second; j++)
            s[j] = 'W';
        } else {
          for (int j = len[i].second.second; j >= len[i].second.first; j--)
            s[j] = 'W';
        }
      } else {
        if (len[i].second.first != 0) {
          for (int j = len[i].second.first; j <= len[i].second.second; j++) {
            if (k == 0) break;
            s[j] = 'W';
            k--;
          }
          break;
        } else {
          for (int j = len[i].second.second; j >= len[i].second.first; j--) {
            if (k == 0) break;
            s[j] = 'W';
            k--;
          }
          break;
        }
      }
    }
    int ans = 0;
    i = 0;
    while (i < n) {
      if (s[i] == 'L') {
        i++;
        continue;
      }
      int ct = 0;
      while (s[i] == 'W') {
        ct++;
        i++;
      }
      ans += 1 + (ct - 1) * 2;
    }
    cout << ans << '\n';
  }
}
