#include <bits/stdc++.h>
using namespace std;
long long int power(long long int b, long long int e) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a == b) return a;
  if (a > b) return gcd(a - b, b);
  return gcd(a, b - a);
}
bool compare(const pair<long long int, long long int>& i,
             const pair<long long int, long long int>& j) {
  return i.first < j.first;
}
void solve() {
  long long int n, sum = 0, k, ans = 0, l1 = 0, a = 0, flag = 0, f = 1;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<long long int> v;
  for (long long int i = 0; i < n; i++) {
    if (f == 1) {
      if (s[i] == 'L')
        l1++;
      else {
        f = 2;
        flag = 1;
      }
    } else if (flag == 0) {
      if (s[i] == 'W') {
        flag = 1;
        v.push_back(a);
        a = 0;
      } else
        a++;
    } else {
      f++;
      if (s[i] == 'L') {
        a++;
        flag = 0;
      }
    }
  }
  if (s[0] == 'W') ans++;
  for (long long int i = 1; i < n; i++) {
    if (s[i] == 'W' && s[i - 1] == 'L')
      ans++;
    else if (s[i] == 'W' && s[i - 1] == 'W') {
      ans += 2;
    }
  }
  for (long long int i = 0; i < v.size(); i++) {
  }
  sort(v.begin(), v.end());
  for (long long int i = 0; i < v.size(); i++) {
    if (k >= v[i]) {
      ans += 2 * v[i] + 1;
      k -= v[i];
    } else {
      ans += 2 * k;
      cout << ans << "\n";
      return;
    }
  }
  if (ans == 0) {
    if (l1 < k)
      cout << 2 * l1 - 1 << "\n";
    else {
      if (k)
        cout << 2 * k - 1 << "\n";
      else
        cout << 0 << "\n";
    }
    return;
  }
  if (l1 + a < k) {
    ans += 2 * (l1 + a);
  } else
    ans += 2 * k;
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
}
