#include <bits/stdc++.h>
using namespace std;
using pqboro = priority_queue<long long, vector<long long>, less<long long>>;
using pqchoto =
    priority_queue<long long, vector<long long>, greater<long long>>;
template <typename T>
string toString(T Number) {
  stringstream ss;
  ss << Number;
  return ss.str();
}
template <typename T>
long long toll(T str) {
  stringstream ss;
  ss << str;
  long long num;
  ss >> num;
  return num;
}
const int N = 2e5 + 7;
const int M = 1e9 + 7;
const long long inf = 0x7f7f7f7f7f7f7f7f;
void run_for_testcase() {
  long long n, m, i, j, k, x;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<long long> a;
  long long tot = 0;
  long long cnt = 0;
  i = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == 'W') {
      break;
    }
  }
  for (; i < n; i++) {
    if (s[i] == 'L') {
      ++cnt;
      j = i + 1;
      for (; j < n; j++) {
        if (s[j] == 'W') {
          a.emplace_back(cnt);
          cnt = 0;
          break;
        }
        ++cnt;
      }
      i = j - 1;
    } else {
      ++tot;
      j = i + 1;
      for (; j < n; j++) {
        if (s[j] == 'L') {
          break;
        }
        tot += 2;
      }
      i = j - 1;
    }
  }
  if (tot == 0) {
    cout << max(0LL, 2 * k - 1) << endl;
    return;
  }
  sort(a.begin(), a.end());
  for (i = 0; i < a.size(); i++) {
    if (a[i] <= k) {
      k -= a[i];
      tot += (1 + (a[i] * 2));
    } else {
      tot += (k * 2);
      cout << tot << endl;
      return;
    }
  }
  if (k > 0) {
    if (s.front() == 'L') {
      cnt = 0;
      for (i = 0; i < n; i++) {
        if (s[i] == 'L') {
          ++cnt;
        } else
          break;
      }
      if (k > cnt) {
        tot += (cnt * 2);
        k -= cnt;
      } else {
        tot += (k * 2);
        cout << tot << endl;
        return;
      }
    }
  }
  if (k > 0) {
    if (s.back() == 'L') {
      cnt = 0;
      for (i = n - 1; i >= 0; i--) {
        if (s[i] == 'L')
          ++cnt;
        else
          break;
      }
      tot += (min(k, cnt) * 2);
    }
  }
  cout << tot << endl;
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) run_for_testcase();
  return 0;
}
