#include <bits/stdc++.h>   using namespace std;   template <typename T>   void tk_input(vector<T> &arr) {     for (T &i : arr) cin >> i;   }   void solve() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         pq;     int sc = 0, ls = 0, ls_i = 0, f_i = n, l_i = -1;     for (int i = 0; i <= n - 1; i++) {       if (s[i] ==  W ) {         if ((ls > 0) && (f_i != n)) pq.push(pair<int, int>(ls, ls_i));         f_i = min(f_i, i);         l_i = max(l_i, i);         ls_i = i + 1;         ls = 0;       } else {         ls++;       }     }     while ((!pq.empty()) && (k > 0)) {       auto tp = pq.top();       pq.pop();       for (int i = tp.second; i <= tp.first + tp.second - 1; i++) {         if (k == 0) break;         s[i] =  W ;         k--;       }     }     for (int i = f_i - 1; i >= 0; i--) {       if (k == 0) break;       s[i] =  W ;       k--;     }     if (l_i != -1) {       for (int i = l_i + 1; i <= n - 1; i++) {         if (k == 0) break;         s[i] =  W ;         k--;       }     }     sc += (s[0] ==  W );     for (int i = 1; i <= n - 1; i++) {       sc += ((s[i] ==  W ) * (1 + (s[i - 1] ==  W )));     }     cout << sc <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int _t;     cin >> _t;     while (_t--) solve();   }   