#include <bits/stdc++.h>
using namespace std;
bool customSort(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) {
    return a.second > b.second;
  }
  return a.first < b.first;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string str;
    cin >> str;
    str = "L" + str + "L";
    vector<int> p1, p2, p3;
    int totw = 0;
    vector<int> wind;
    int score = 0;
    for (int i = 1; i <= n; i++) {
      if (str[i] == 'W') {
        totw++;
        score++;
        if (str[i - 1] == 'W') {
          score++;
        }
        wind.push_back(i);
      }
    }
    if (totw == 0) {
      for (int i = 1; i <= k; i++) {
        str[i] = 'W';
        score++;
        if (str[i - 1] == 'W') {
          score++;
        }
      }
    } else if (totw + k >= n) {
      for (int i = 1; i <= n; i++) {
        str[i] = 'W';
      }
      score = (n - 1) * 2 + 1;
    } else {
      vector<pair<int, int>> gaps;
      for (int i = 1; i < wind.size(); i++) {
        if (wind[i] - wind[i - 1] - 1 > 0) {
          gaps.push_back(
              {wind[i] - wind[i - 1] - 1, 2 * (wind[i] - wind[i - 1] - 1) + 1});
        }
      }
      sort(gaps.begin(), gaps.end(), customSort);
      int ind = 0;
      while (k > 0) {
        if (ind >= gaps.size()) {
          break;
        }
        int replace = gaps[ind].first;
        if (k >= replace) {
          k -= replace;
          score += gaps[ind].second;
        } else {
          score += k * 2;
          k = 0;
        }
        ind++;
      }
      if (k > 0) {
        score += 2 * k;
      }
    }
    cout << score << endl;
  }
}
