#include <bits/stdc++.h>
using namespace std;
void toUpperCase(string s) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] >= 'a' && s[i] <= 'z') {
      s[i] = s[i] - 32;
    }
  }
  cout << s;
}
bool isPrime(int n) {
  if (n <= 1) return false;
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0) return false;
  return true;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long kqua = 0;
    long long n, k, i;
    cin >> n >> k;
    string s;
    cin >> s;
    s = ' ' + s;
    int check = 0;
    long long a[100001];
    long long b[100001];
    a[0] = 0;
    for (i = 1; i <= n; i++) {
      if (s[i] == 'W') {
        if (s[i - 1] == 'W') {
          kqua += 2;
        } else
          kqua += 1;
      }
    }
    if (k == 0) {
      cout << kqua << endl;
      continue;
    }
    if (kqua == 0) {
      cout << k * 2 - 1 << endl;
      continue;
    }
    for (i = 1 + (s[1] == 'L'); i <= n - (s[n] == 'L'); i++) {
      if (s[i] == 'W') {
        check = check + 1;
        a[check] = i;
      }
    }
    for (i = 2; i <= check; i++) {
      b[i] = a[i] - a[i - 1] - 1;
    }
    sort(b + 1, b + check + 1);
    for (i = 1; i <= check; i++)
      if (b[i])
        if (k >= b[i]) {
          kqua = kqua + b[i] * 2 + 1;
          k = k - b[i];
          if (k == 0) break;
        } else {
          kqua += k * 2;
          k = 0;
          break;
        }
    if (k) {
      kqua = min(kqua + k * 2, n * 2 - 1);
    }
    kqua = min(kqua, n * 2 - 1);
    cout << kqua << endl;
  }
  return 0;
}
