#include <bits/stdc++.h>
using namespace std;
char a[130000];
struct gg {
  int x, y, z;
} b[130000];
int cmp(gg p, gg q) { return p.z < q.z; }
void solve() {
  int n, m;
  cin >> n >> m;
  cin >> a;
  int l = 0;
  int p = 0, q = 0, o = 0;
  for (int i = 0; i < n; i++)
    if (a[i] == 'W') {
      p = i;
      o = i;
      break;
    }
  for (int i = 0; i < n; i++) {
    if (a[i] == 'W') {
      q = i;
      b[l].x = p;
      b[l].z = q - p - 1;
      b[l++].y = q;
      p = q;
    }
  }
  sort(b, b + l, cmp);
  for (int i = 0; i < l && m > 0; i++) {
    int gg = b[i].x, hh = b[i].y;
    for (int j = gg + 1; j < hh && m > 0; j++)
      if (a[j] == 'L') {
        a[j] = 'W';
        m--;
      }
  }
  for (int i = o; i >= 0 && m > 0; i--)
    if (a[i] == 'L') {
      a[i] = 'W';
      m--;
    }
  for (int i = q; i < n && m > 0; i++)
    if (a[i] == 'L') {
      a[i] = 'W';
      m--;
    }
  int s = 0;
  for (int i = 0; i < n; i++)
    if (a[i] == 'W') {
      if (i == 0 || a[i - 1] != 'W')
        s++;
      else
        s += 2;
    }
  printf("%d\n", s);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
