#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.second == b.second) return (a.first < b.first);
  return (a.second < b.second);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long mi = 1e12, ma = -1e12;
  long long a, b, c, d, n, ex, m, k, sum = 0, no = 0, s = 0, tt, mod = 1e9 + 7,
                                     x, y, w = 0;
  char ch;
  string C;
  vector<long long> A, B, T;
  set<long long> St;
  cin >> ex;
  while (ex--) {
    s = 0;
    w = 0;
    no = 0;
    cin >> n >> k >> C;
    for (int i = 0; i < n; i++) {
      if (C[i] == 'W') {
        w++;
        no = 1;
      }
      if (C[i] == 'L' && no) {
        s++;
      } else {
        if (s) A.push_back(s);
        s = 0;
      }
    }
    w += min(k, n - w);
    if (w == 0 && k == 0)
      cout << 0;
    else {
      sort(A.begin(), A.end());
      reverse(A.begin(), A.end());
      for (int i = A.size() - 1; i >= 0; i--) {
        if (A[i] <= k) {
          k -= A[i];
          A.pop_back();
        }
      }
      cout << 2 * w - (A.size() + 1);
    }
    cout << '\n';
    ;
    A.clear();
  }
}
