#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int t, n, K;
char ch[maxn];
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> K >> ch + 1;
    ch[0] = 'L';
    int q = 0, res = 0;
    for (int i = 1; i <= n; i++) {
      res += (ch[i] == 'W') + (ch[i] == 'W' && ch[i - 1] == 'W');
    }
    vector<int> v;
    int i = 1;
    while (i <= n && ch[i] == 'L') i++;
    if (i == n + 1) {
      if (K)
        cout << 2 * min(K, n) - 1 << "\n";
      else
        cout << "0\n";
      continue;
    }
    q += i - 1;
    for (int j; i <= n; i = j) {
      j = i;
      while (j <= n && ch[j] == 'W') j++;
      int k = j;
      while (j <= n && ch[j] == 'L') j++;
      if (j <= n)
        v.push_back(j - k);
      else
        q += j - k;
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size() && K; i++) {
      if (K >= v[i]) {
        res += v[i] * 2 + 1;
        K -= v[i];
      } else {
        res += K * 2;
        K = 0;
      }
    }
    if (K) {
      res += 2 * min(q, K);
    }
    cout << res << "\n";
  }
}
