#include <bits/stdc++.h>
using namespace std;
const long double EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (long long)INF * (long long)INF;
const long long MOD = 1e9 + 7;
const long double PI = 3.14159265358979323846;
struct HASH {
  size_t operator()(const pair<int, int> &x) const {
    return hash<long long>()(((long long)x.first) ^
                             (((long long)x.second) << 32));
  }
};
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '[';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "]";
}
void _print() { cerr << "\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
struct Offset {
  set<long long> s;
  long long delta;
  long long getMinimum() { return (*s.begin()) + delta; }
  long long getMaximum() { return (*s.rbegin()) + delta; }
  void increase(long long x) { delta += x; }
  void add(long long x) { s.insert(x - delta); }
  void remove(long long x) { s.erase(x - delta); }
  bool contains(long long x) { return s.count(x - delta) != 0; }
};
long long solve(int n, int k, string s) {
  int wins = 0, losses = 0;
  vector<pair<int, int>> w, l;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'W') {
      wins++;
      if (losses) {
        l.push_back(make_pair(i - losses, losses));
        losses = 0;
      }
    } else {
      losses++;
      if (wins) {
        w.push_back(make_pair(i - wins, wins));
        wins = 0;
      }
    }
  }
  if (losses) {
  }
  if (wins) {
    w.push_back(make_pair(n - wins, wins));
  }
  sort(l.begin(), l.end(), [](const pair<int, int> l, const pair<int, int> r) {
    return l.second < r.second;
  });
  int score = 0;
  int first_pos = -1;
  for (int i = 0; i < l.size(); i++) {
    if (l[i].first == 0) {
      first_pos = i;
      continue;
    }
    if (l[i].second <= k) {
      for (int j = l[i].first; j < l[i].first + l[i].second; j++) {
        s[j] = 'W';
      }
      k -= l[i].second;
    } else {
      for (int j = l[i].first; j < l[i].first + k; j++) {
        s[j] = 'W';
      }
      k = 0;
      break;
    }
  }
  if (k > 0 && losses) {
    int pos = n - losses;
    int c = k;
    for (int j = pos; j < min(pos + c, n); j++) {
      s[j] = 'W';
      k--;
    }
  }
  if (k > 0 && first_pos != -1) {
    for (int j = l[first_pos].second; j >= max(0, l[first_pos].second - k);
         j--) {
      s[j] = 'W';
    }
  }
  if (s[0] == 'W') {
    score++;
  }
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == 'W' && s[i] == 'W') {
      score += 2;
    } else if (s[i] == 'W') {
      score += 1;
    }
  }
  return score;
}
long long brute(int n, int k, string s) {
  vector<int> z;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'L') {
      z.push_back(i);
    }
  }
  int ans = -1;
  for (int mask = 0; mask < (1 << z.size()); mask++) {
    if (__builtin_popcount(mask) <= k) {
      string cop = s;
      for (int i = 0; i < z.size(); i++) {
        if (mask & (1 << i)) {
          cop[z[i]] = 'W';
        }
      }
      int score = 0;
      if (cop[0] == 'W') {
        score++;
      }
      for (int i = 1; i < n; i++) {
        if (cop[i - 1] == 'W' && cop[i] == 'W') {
          score += 2;
        } else if (cop[i] == 'W') {
          score += 1;
        }
      }
      ans = max(ans, score);
    }
  }
  return ans;
}
long long rand(long long a, long long b) { return a + rand() % (b - a + 1); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    cout << solve(n, k, s) << "\n";
  }
  return 0;
}
