#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, l, m, n, p, t, a, b, c;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    string s;
    cin >> s;
    p = 0;
    vector<long long int> freq;
    m = 0;
    for (i = 0; i < n; i++) {
      if (s[i] != 'L') {
        break;
      } else {
        m++;
      }
    }
    a = i;
    for (i = a; i < n;) {
      l = 0;
      b = 1;
      for (j = i + 1; j < n; j++) {
        if (s[j] == 'W')
          b += 2;
        else
          break;
      }
      i = j;
      p += b;
      for (c = j; c < n; c++) {
        if (s[c] == 'L') {
          l++;
          m++;
        } else
          break;
      }
      i = c;
      if (i != n) freq.push_back(l);
    }
    sort(freq.begin(), freq.end());
    i = 0;
    while (k > 0 && i < freq.size()) {
      if (k >= freq[i]) {
        p += (1 + freq[i] * 2);
        k = k - freq[i];
        m = m - freq[i];
      } else
        break;
      i++;
    }
    if (k > 0) {
      if (p == 0) {
        p--;
      }
      p += (min(m, k) * 2);
    }
    cout << p << "\n";
  }
}
