#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template <typename T>
bool mmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T>
bool mmin(T &m, const T q) {
  if (m > q) {
    m = q;
    return true;
  } else
    return false;
}
void __print(long long first) { cerr << first; }
void __print(long first) { cerr << first; }
void __print(unsigned first) { cerr << first; }
void __print(unsigned long first) { cerr << first; }
void __print(unsigned long long first) { cerr << first; }
void __print(float first) { cerr << first; }
void __print(double first) { cerr << first; }
void __print(long double first) { cerr << first; }
void __print(char first) { cerr << '\'' << first << '\''; }
void __print(const char *first) { cerr << '\"' << first << '\"'; }
void __print(const string &first) { cerr << '\"' << first << '\"'; }
void __print(bool first) { cerr << (first ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &first) {
  cerr << '{';
  __print(first.first);
  cerr << ',';
  __print(first.second);
  cerr << '}';
}
template <typename T>
void __print(const T &first) {
  long long f = 0;
  cerr << '{';
  for (auto &i : first) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long N = 1 << 20;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  long long T;
  cin >> T;
  while (T--) {
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    long long f = 0, ans = 0, c = 0, pre = 0, suf = 0;
    ;
    vector<long long> v;
    for (long long i = 0; i < n; i++) {
      if (s[i] == 'L') {
        c++;
      } else {
        if (f) {
          if (c) v.push_back(c);
        } else
          pre = c;
        c = 0;
        f = 1;
        if (i - 1 >= 0 and s[i - 1] == 'W')
          ans += 2;
        else
          ans++;
      }
    }
    suf = c;
    if (k == 0) {
      cout << ans << "\n";
      continue;
    }
    if (suf == n) {
      mmin(k, suf);
      ans += (k - 1) * 2;
      ans++;
      cout << ans << "\n";
      continue;
    }
    sort((v).begin(), (v).end());
    for (auto i : v) {
      if (i <= k) {
        ans += 2 * i;
        ans++;
        k -= i;
      } else {
        ans += 2 * k;
        k = 0;
        break;
      }
    }
    long long d = min(k, pre);
    ans += d * 2;
    k -= d;
    ans += min(k, suf) * 2;
    cout << ans << "\n";
  }
  return 0;
}
