#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k, temp;
    cin >> n >> k;
    temp = k;
    string s;
    cin >> s;
    int ans = 0;
    if (s[0] == 'W') ans++;
    for (int i = 1; i < n; i++) {
      if (s[i] == 'W' && s[i - 1] == 'W')
        ans += 2;
      else if (s[i] == 'W')
        ans++;
    }
    int cnt = 0, flag = 0;
    vector<int> v;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'W') {
        if (cnt && flag) v.push_back(cnt);
        cnt = 0;
        flag = 1;
      } else {
        cnt++;
      }
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
      if (k >= v[i]) {
        ans += (2 * v[i] + 1);
        k -= v[i];
      } else {
        ans += (2 * k);
        k = 0;
        break;
      }
    }
    if (k > 0) {
      for (int i = 0; i < n; i++) {
        if (k == 0 || s[i] == 'W') break;
        s[i] = 'W';
        ans += 2;
        k--;
      }
      for (int i = n - 1; i >= 0; i--) {
        if (k == 0 || s[i] == 'W') break;
        ans += 2;
        k--;
      }
    }
    if (flag == 0 && temp != 0) ans--;
    cout << ans << endl;
  }
  return 0;
}
