#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    string s;
    cin >> n >> k >> s;
    int loss = 0, prev = -1, score = 0;
    vector<int> gaps;
    int gap = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'L') {
        gap++;
        loss++;
      } else if (s[i] == 'W') {
        score++;
        if (i && s[i - 1] == 'W') {
          score++;
        }
        if (gap && prev >= 0) {
          gaps.push_back(gap);
        }
        gap = 0;
        prev = i;
      }
    }
    sort(gaps.begin(), gaps.end());
    k = min(k, loss);
    for (int i = 0; i < gaps.size() && k - gaps[i] >= 0; i++) {
      k -= gaps[i];
      score += 2 * gaps[i] + 1;
    }
    score += 2 * k;
    if (loss == n && k > 0) {
      score--;
    }
    cout << score << '\n';
  }
}
