#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    char arr[n];
    int score = 0;
    char last = 'O';
    int gapLen = 0;
    int startGap = 0;
    int endGap = 0;
    vector<int> gaps;
    for (int i = 0; i < n; i++) {
      cin >> arr[k];
      if (arr[k] == 'W' && last == 'W')
        score += 2;
      else if (arr[k] == 'W' && last == 'L' && score > 0) {
        score++;
        gaps.push_back(gapLen);
        gapLen = 0;
      } else if (arr[k] == 'W' && last == 'L' && score == 0) {
        score++;
        startGap = gapLen;
        gapLen = 0;
      } else if (arr[k] == 'W' && last == 'O')
        score++;
      else if (arr[k] == 'L')
        gapLen++;
      last = arr[k];
    }
    endGap = gapLen;
    sort(gaps.begin(), gaps.end());
    for (int i = 0; i < gaps.size(); i++) {
      if (k > gaps[i]) {
        k -= gaps[i];
        score += 3 + 2 * (gaps[i] - 1);
      } else if (k == gaps[i]) {
        score += 3 + 2 * (gaps[i] - 1);
        k = 0;
        break;
      } else {
        score += 2 * k;
        k = 0;
        break;
      }
    }
    if (k > 0 && score != 0) {
      int restGap = startGap + endGap;
      if (k >= restGap) {
        score += 2 * restGap;
      } else {
        score += 2 * k;
      }
    } else if (k > 0 && score == 0) {
      score += 1 + 2 * (k - 1);
    }
    cout << score << endl;
  }
}
