#include <bits/stdc++.h>
int main() {
  int t;
  std::cin >> t;
  for (int p = 0; p < t; p++) {
    int n;
    int k;
    std::cin >> n >> k;
    std::string word;
    std::cin >> word;
    std::vector<char> a(word.begin(), word.end());
    std::vector<int> values;
    bool left = false;
    bool right = false;
    if (a[0] == 'L') {
      left = true;
    }
    if (a[a.size() - 1] == 'L') {
      right = true;
    }
    int local = 0;
    for (int i = 0; i < a.size(); i++) {
      if (a[i] == 'L') {
        local++;
      }
      if (a[i] == 'W' && local != 0) {
        values.push_back(local);
        local = 0;
      }
    }
    if (local != 0) {
      values.push_back(local);
      local = 0;
    }
    int m = 0;
    std::vector<int> b;
    if (!left && !right) {
      b = values;
      std::sort(b.begin(), b.end());
    }
    if (left && !right) {
      b = values;
      b[0] = 3000000;
      std::sort(b.begin(), b.end());
    }
    if (!left && right) {
      b = values;
      b.pop_back();
      std::sort(b.begin(), b.end());
    }
    if (left && right) {
      b = values;
      b.pop_back();
      b[0] = 3000000;
      std::sort(b.begin(), b.end());
    }
    int sum = 0;
    for (int j = 0; j < b.size() && (sum + b[j] <= k); j++) {
      sum += b[j];
      m++;
    }
    int points = 0;
    for (int i = 0; i < a.size() - 1; i++) {
      if (a[i] == 'W') {
        points++;
      }
      if (a[i] == 'W' && a[i + 1] == 'W') {
        points++;
      }
    }
    if (!right) {
      points++;
    }
    points += m;
    int suml = 0;
    for (int i = 0; i < values.size(); i++) {
      suml += values[i];
    }
    if (suml == a.size() && k > 0) {
      points += 2 * std::min(suml, k);
      points--;
    } else {
      points += 2 * std::min(suml, k);
    }
    std::cout << points << std::endl;
  }
  return 0;
}
