#include <bits/stdc++.h>
using namespace std;
const long double epsylon = 1e-9;
const std::string PROGRAM_NAME = "ivo";
int main() {
  int nt;
  cin >> nt;
  for (int it = 0; it < nt; ++it) {
    int n, k;
    cin >> n >> k;
    string s;
    getline(cin, s);
    getline(cin, s);
    vector<int> a;
    int c = 0;
    for (int i = 0; i < (int)s.size(); ++i) {
      if (s[i] == 'W') {
        if (c) {
          if (c == i) {
            c += 1000000;
          }
          a.push_back(c);
          c = 0;
        }
      } else {
        c++;
      }
    }
    if (c) {
      if (c == (int)s.size()) {
        c += 1000000;
      }
      c += 1000000;
      a.push_back(c);
    }
    sort(a.begin(), a.end());
    int score = 0;
    for (int i = 0; i < (int)s.size(); ++i) {
      if (s[i] == 'W') {
        if (i > 0 && s[i - 1] == 'W') {
          score += 2;
        } else {
          score += 1;
        }
      }
    }
    for (int i = 0; i < (int)a.size() && k > 0; ++i) {
      int sub = 0;
      while (a[i] > 1000000) {
        a[i] -= 1000000;
        sub++;
      }
      if (k < a[i]) {
        score += 2 * k;
        score -= max(0, sub - 1);
        k = 0;
      } else {
        score += 2 * a[i] + 1;
        score -= sub;
        k -= a[i];
      }
    }
    cout << score << endl;
  }
  return 0;
}
