#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  int t, n, k, cnt;
  string boi;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    cin >> boi;
    cnt = 0;
    for (int i = 0; i < n; i++) cnt += (boi[i] == 'W');
    if (cnt == 0) {
      cout << max(2 * k - 1, 0) << '\n';
      continue;
    }
    if (n == 1 and k == 1 and boi == "L") {
      cout << "1\n";
      continue;
    }
    if (n == 1 and boi == "L") {
      cout << "0\n";
      continue;
    }
    vector<int> zero;
    int temp = 1, sum = 0, anfang = 0, schluss = 0;
    if (boi[0] == 'L') {
      for (int i = 0; i < n; i++)
        if (boi[i] == 'L')
          anfang++;
        else
          break;
    }
    if (boi[n - 1] == 'L') {
      for (int i = n - 1; i >= 0; i--)
        if (boi[i] == 'L')
          schluss++;
        else
          break;
    }
    if (boi[anfang] == 'W') sum++;
    for (int i = 1 + anfang; i < n - schluss; i++) {
      if (boi[i] == boi[i - 1] and boi[i] == 'L') {
        temp++;
      } else if (boi[i] == 'W' and boi[i - 1] == 'L') {
        zero.push_back(temp);
        temp = 1;
      }
      if (boi[i] == 'W') {
        sum++;
        if (i != 0 and boi[i - 1] == 'W') sum++;
      }
    }
    for (int i = 0; i < zero.size(); i++) {
      zero[i] = 2 * zero[i] + 1;
    }
    if (anfang > schluss) swap(anfang, schluss);
    sort(zero.begin(), zero.end());
    bool a = false, s = false;
    for (auto it : zero) {
      if (k == 0) break;
      if (k >= it / 2) {
        k -= it / 2;
        sum += it;
      } else {
        sum += 2 * k;
        k = 0;
      }
    }
    if (!a) {
      if (k >= anfang) {
        k -= anfang;
        sum += 2 * anfang;
      } else {
        sum += 2 * k;
        k = 0;
      }
      a = true;
    }
    if (!s) {
      if (k >= schluss) {
        k -= schluss;
        sum += 2 * schluss;
      } else {
        sum += 2 * k;
        k = 0;
      }
      s = true;
    }
    cout << sum << '\n';
  }
  return 0;
}
