#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    string s;
    cin >> n >> k >> s;
    int ans = 0;
    list<pair<int, int>> a;
    int i = 0;
    while (i < n) {
      int l = 0, w = 0, f1 = 0, f2 = 0;
      while (i < n && s[i] == 'L') f1 |= (i == 0), f2 |= (i == n - 1), ++i, ++l;
      while (i < n && s[i] == 'W') ++i, ++w;
      int y = f1 + f2;
      if (l) a.push_back(make_pair(y, l));
      if (w) ans += 2 * w - 1;
    }
    a.sort();
    while (k && a.size()) {
      int y = a.front().first;
      int l = a.front().second;
      int m = min(l, k);
      if (y == 0 && m == l) ans += 2 * m + 1;
      if (y == 0 && m < l) ans += 2 * m;
      if (y == 1) ans += 2 * m;
      if (y == 2) ans += 2 * m - 1;
      k -= m;
      a.pop_front();
    }
    cout << ans << "\n";
  }
}
