#include <bits/stdc++.h>
using namespace std;
struct P {
  int x, y;
  bool operator<(const P &a) const { return y > a.y; };
};
int a, b, c, d, i, n, m, e, k, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1},
                               dy[10] = {0, 1, 0, -1, 1, -1, 1, -1};
int o[111];
int l[1];
int ss[1];
long long x, y, z, mod = 1000000007, hf = (mod + 1) / 2;
char r[101111];
vector<int> v[1];
P u[1];
priority_queue<int, vector<int>, greater<int> > q;
set<int> s[1];
map<int, int> p;
bool as(P a, P b) { return a.y < b.y; }
int main() {
  int ttt;
  scanf("%d", &ttt);
  for (int tt = 1; tt <= ttt; tt++) {
    scanf("%d %d", &a, &b);
    scanf("%s", r + 1);
    k = 0;
    priority_queue<int, vector<int>, greater<int> > q;
    e = 0;
    m = 0;
    for (int t = 1; t <= a; t++) {
      if (r[t] == 'W') {
        k += 2;
        if (e) {
          k--;
          if (e + 1 != t) q.push(e);
        } else if (t == 1)
          k--;
        e = 0;
      } else
        e++;
    }
    n = 0;
    m = a + 1;
    for (int t = 1; t <= a; t++)
      if (r[t] == 'L')
        n = t;
      else
        break;
    for (int t = a; t; t--)
      if (r[t] == 'L')
        m = t;
      else
        break;
    if (1 == m && n == a)
      m = 0;
    else
      m = a - m + 1;
    if (n + m == a) {
      printf("%d\n", max(min(a, b) * 2 - 1, 0));
      continue;
    }
    for (; b && q.size(); q.pop()) {
      if (b >= q.top()) {
        k++;
        k += q.top() * 2;
        b -= q.top();
      } else {
        k += b * 2;
        b = 0;
      }
    }
    k += min(b, n + m) * 2;
    printf("%d\n", k);
  }
}
