#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k, n_w = -1, s1 = 0;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'W') {
      s1++;
      if (i > 0 && s[i - 1] == 'W') s1++;
    }
  }
  if (s1 == 0) {
    if (k == 0)
      cout << 0 << endl;
    else
      cout << k * 2 - 1 << endl;
    return;
  }
  for (int i = 0; i < n; i++)
    if (s[i] == 'W') {
      n_w = i;
      break;
    }
  int l_w = n_w;
  for (int i = n_w + 1; i < n; i++) {
    if (s[i] == 'W') {
      if (i - l_w - 1 > 0) a.push_back(i - l_w - 1);
      l_w = i;
    }
  }
  sort(a.begin(), a.end());
  int ss = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] <= k) {
      k -= a[i];
      ss += a[i] * 2 + 1;
    } else {
      ss += k * 2;
      k = 0;
    }
  }
  if (k > 0) {
    ss += min(n_w, k) * 2;
    k -= min(n_w, k);
  }
  if (k > 0) {
    ss += min(n - l_w - 1, k) * 2;
    k -= min(n - l_w - 1, k);
  }
  cout << ss + s1 << endl;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    solve();
  }
}
