#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
int n, k;
int hx[26]{};
void solve()
{
cin >> n >> k;
string s;
cin >> s;
int ans = 0;
for (auto& c : s)
{
hx[c - 'A']++;
if (c == 'W')
{
if (hx['W' - 'A'] >= 3)ans += k;
else ans += 1;
}
else {
hx['W' - 'A'] = 0;
ans -= 1;
}
}
cout << ans << '\n';
memset(hx,0,sizeof hx);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--)solve();
return 0;
}
class Solution {
public:
int maxLength(vector<int>& arr) {
int ans = 1;
int n = arr.size();
unordered_map<int,int>hashmap;
int left = 0,right = 0;
while(right<n)
{
hashmap[arr[right]]++;
while(left<right&&hashmap[arr[right]]>1)
{
int out = arr[left++];
hashmap[out]--;
}
ans = max(ans,right-left+1);
++right;
}
return ans;
}
};
#include <iostream>
using namespace std;
const int N = 100010;
int n;
char s[N];
char ret[N];
int main()
{
cin >> n >> s;
int hash[26] = { 0 };
int maxIndex, maxCount = 0;
for (int i = 0; i < n; i++)
{
if (maxCount < ++hash[s[i] - 'a'])
{
maxCount = hash[s[i] - 'a'];
maxIndex = s[i] - 'a';
}
}
if (maxCount > (n + 1) / 2) cout << "no" << endl;
else
{
cout << "yes" << endl;
int index = 0;
while (maxCount--)
{
ret[index] = maxIndex + 'a';
index += 2;
}
for (int i = 0; i < 26; i++)
{
if (hash[i] && i != maxIndex)
{
while (hash[i]--)
{
if (index >= n) index = 1;
ret[index] = i + 'a';
index += 2;
}
}
}
for (int i = 0; i < n; i++) cout << ret[i];
cout << endl;
}
return 0;
}