You like playing chess tournaments online.

In your last tournament you played $n$ games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get $0$ points. When you win you get $1$ or $2$ points: if you have won also the previous game you get $2$ points, otherwise you get $1$ point. If you win the very first game of the tournament you get $1$ point (since there is not a "previous game").

The outcomes of the $n$ games are represented by a string $s$ of length $n$: the $i$-th character of $s$ is W if you have won the $i$-th game, while it is L if you have lost the $i$-th game.

After the tournament, you notice a bug on the website that allows you to change the outcome of at most $k$ of your games (meaning that at most $k$ times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug.

Compute the maximum score you can get by cheating in the optimal way.


-----Input-----

Each test contains multiple test cases. The first line contains an integer $t$ ($1\le t \le 20,000$) — the number of test cases. The description of the test cases follows.

The first line of each testcase contains two integers $n, k$ ($1\le n\le 100,000$, $0\le k\le n$) – the number of games played and the number of outcomes that you can change.

The second line contains a string $s$ of length $n$ containing only the characters W and L. If you have won the $i$-th game then $s_i=\,$W, if you have lost the $i$-th game then $s_i=\,$L.

It is guaranteed that the sum of $n$ over all testcases does not exceed $200,000$.


-----Output-----

For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way.


-----Example-----
Input
8
5 2
WLWLL
6 5
LLLWWL
7 1
LWLWLWL
15 5
WWWLLLWWWLLLWWW
40 7
LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL
1 0
L
1 1
L
6 1
WLLWLW

Output
7
11
6
26
46
0
1
6



-----Note-----

Explanation of the first testcase. Before changing any outcome, the score is $2$. Indeed, you won the first game, so you got $1$ point, and you won also the third, so you got another $1$ point (and not $2$ because you lost the second game).

An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is $7=1+2+2+2$: $1$ point for the first game and $2$ points for the second, third and fourth game.

Explanation of the second testcase. Before changing any outcome, the score is $3$. Indeed, you won the fourth game, so you got $1$ point, and you won also the fifth game, so you got $2$ more points (since you won also the previous game).

An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is $11 = 1+2+2+2+2+2$: $1$ point for the first game and $2$ points for all the other games.

Starter code:

Solutions:
import sys
input = sys.stdin.readline

def main():
    n, k = map(int, input().split())
    string = input().strip()
    if "W" not in string:
        ans = min(n, k) * 2 - 1
        print(max(ans, 0))
        return
        
    L_s = []
    cnt = 0
    bef = string[0]
    ans = 0
    for s in string:
        if s == bef:
            cnt += 1
        else:
            if bef == "L":
                L_s.append(cnt)
            else:
                ans += cnt * 2 - 1
            cnt = 1
        bef = s
    if bef == "W":
        ans += cnt * 2 - 1
        cnt = 0
        
    if string[0] == "L" and L_s:
        cnt += L_s[0]
        L_s = L_s[1:]
    L_s.sort()
    for l in L_s:
        if k >= l:
            ans += l * 2 + 1
            k -= l
        else:
            ans += k * 2
            k = 0
            
    ans += 2 * min(k, cnt)
    print(ans)
    
    
    
for _ in range(int(input())):
    main()

import sys

input = sys.stdin.readline

for _ in range(int(input())):
    n,k = map(int,input().split())
    s = input()
    s = [s[i] for i in range(n)]

    base = s.count("W")
    if base == 0:
        if k:
            print(2*k-1)
        else:
            print(0)
    elif base+k>=n:
        print(2*n-1)
    else:
        interval = []
        while s and s[-1]=="L":
            s.pop()
        s = s[::-1]
        while s and s[-1]=="L":
            s.pop()

        while s:
            if s[-1]=="W":
                while s and s[-1]=="W":
                    s.pop()
            else:
                tmp = 0
                while s and s[-1]=="L":
                    s.pop()
                    tmp += 1
                interval.append(tmp)
        interval.sort(reverse=True)
        K = k
        while interval and k:
            if k>=interval[-1]:
                k -= interval.pop()
            else:
                break
        print(2*(base+K)-1-len(interval))

import sys
input = sys.stdin.readline


def compress(string):
    string = string + "#"
    n = len(string)
    begin, end, cnt = 0, 1, 1
    ans = []
    while end < n:
        if string[begin] == string[end]:
            end, cnt = end + 1, cnt + 1
        else:
            ans.append((string[begin], cnt))
            begin, end, cnt = end, end + 1, 1
    return ans


t = int(input())
for _ in range(t):
    n, k = map(int, input().split())
    s = input()[:-1]
    
    s = compress(s)

    
    w_groups = 0
    w_cnt = 0
    l_cnt = 0
    li = []
    for i, (char, cnt) in enumerate(s):
        if char == "W":
            w_groups += 1
            w_cnt += cnt
        if char == "L":
            l_cnt += cnt
            if 1 <= i < len(s) - 1:
                li.append(cnt)

    if w_cnt == 0:
        print(max(min(k, l_cnt) * 2 - 1, 0))
        continue
        
    ans = w_cnt * 2 - w_groups
    ans += min(k, l_cnt) * 2

    li.sort()
    for val in li:
        if k >= val:
            ans += 1
            k -= val
    print(ans)

for _ in range(int(input())):
    n, k = list(map(int, input().split()))
    s = input()
    k = min(k, s.count("L"))
    arr = []
    cur = 0
    sc = 0
    se = False
    if s[0] == "W":
        sc += 1
    for e in s:
        if e == "L":
            cur += 1
        else:
            if cur > 0 and se:
                arr.append(cur)
            se = True
            cur = 0
    for i in range(1, n):
        if s[i] == "W":
            if s[i-1] == "W":
                sc += 2
            else:
                sc += 1 
    arr.sort() 
    arr.reverse()
    #print(arr, sc)
    while len(arr) > 0 and arr[-1] <= k:
        k -= arr[-1]
        sc += arr[-1]*2+1
        arr.pop()
    #print(k)
    sc += k*2
    if k > 0 and s.count("W") == 0:
        sc -= 1
    print(sc)


from sys import stdin

t = int(stdin.readline())
for i in range(t):
    n, k = tuple(int(x) for x in stdin.readline().split())
    line = 'L' * (k+1) + stdin.readline()[:-1] + 'L' * (k+1)
    score = 0
    flag = False
    for char in line:
        if char == 'W':
            if flag:
                score += 2
            else:
                score += 1
                flag = True
        else:
            flag = False
            
    seq = sorted(len(x) for x in line.split('W'))

    if len(seq) == 1:
        if k == 0:
            print(0)
        else:
            print(2*k-1)
        continue
    for item in seq:
        if item == 0:
            continue
        if k - item >= 0:
            k -= item
            score += 2 * (item-1) + 3
        elif k > 0:
            score += 2 * k
            break
        else:
            break
    print(min(score, 2*n-1))
    


from sys import stdin
"""
n=int(stdin.readline().strip())
n,m=map(int,stdin.readline().strip().split())
s=list(map(int,stdin.readline().strip().split()))
s=stdin.readline().strip()
"""
T=int(stdin.readline().strip())
for caso in range(T):
    n,k=list(map(int,stdin.readline().strip().split()))
    s=list(stdin.readline().strip())
    aux=[]
    last=-1
    for i in range(n):
        if i>0 and s[i]=='L' and s[i-1]=='W':
            last=i
        if i<n-1 and s[i]=='L' and s[i+1]=='W' and last!=-1:
            aux.append([i-last,last,i])
    aux.sort()
    for i in aux:
        for j in range(i[1],i[2]+1):
            if k>0:
                s[j]='W'
                k-=1
    ini=-1
    fin=n
    for i in range(n):
        if s[i]=='W':
            ini=i-1
            break
    for i in range(n-1,-1,-1):
        if s[i]=='W':
            fin=i+1
            break
    for i in range(ini,-1,-1):
        if k>0:
            s[i]='W'
            k-=1
    for i in range(fin,n):
        if k>0:
            s[i]='W'
            k-=1
    ans=0
    if ini==-1 and fin==n:
        for i in range(n):
            if k>0:
                s[i]='W'
                k-=1
    for i in range(n):
        if s[i]=='W':
            if i>0 and s[i-1]=='W':
                ans+=2
            else:
                ans+=1
    print(ans)
            
        
        



for _ in range(int(input())):
    n, k = list(map(int, input().split()))
    inp = input().lower()
    k = min(k, inp.count('l'))
    ans = inp.count('w') + tuple(zip(inp, 'l' + inp)).count('ww') + k * 2
    if 'w' in inp:
        inp2 = []
        cur = -1
        for c in inp:
            if cur != -1:
                if c == 'l':
                    cur += 1
                else:
                    inp2.append(cur)
            if c == 'w':
                cur = 0
        inp2.sort()
        for inp2i in inp2:
            if inp2i > k:
                break
            k -= inp2i
            ans += 1
    else:
        ans = max(ans - 1, 0)
    print(ans)


import sys
readline = sys.stdin.readline

T = int(readline())
Ans = [None]*T

for qu in range(T):
    N, K = list(map(int, readline().split()))
    S = [1 if s == 'W' else 0 for s in readline().strip()]
    if all(s == 0 for s in S):
        Ans[qu] = max(0, 2*K-1)
        continue
    
    ans = 0
    ctr = 0
    st = []
    L = []
    res = 0
    hh = False
    for i in range(N):
        s = S[i]
        if s == 1:
            if i == 0 or S[i-1] == 0:
                ans += 1
            else:
                ans += 2
            if ctr:
                st.append(ctr)
                ctr = 0
            hh = True
        else:
            if hh:    
                ctr += 1
            else:
                res += 1
    res += ctr
    st.sort()
    J = []
    for s in st:
        J.extend([2]*(s-1) + [3])
    J.extend([2]*res)
    Ans[qu] = ans + sum(J[:min(len(J), K)])
print('\n'.join(map(str, Ans)))


def solve():
    n, k = list(map(int, input().split()))
    s = input()
    ans = 0
    prev = False
    c = []
    cc = 0
    for i in range(n):
        if s[i] == 'W':
            if cc:
                if cc != i:
                    c.append(cc)
                cc = 0
            if prev:
                ans += 2
            else:
                ans += 1
            prev = True
        else:
            prev = False
            cc += 1
    c.sort()
    for i in range(len(c)):
        if c[i] <= k:
            k -= c[i]
            ans += c[i] * 2 + 1
    if 'W' in s:
        ans += k * 2
    else:
        ans += max(k * 2 - 1, 0)
    ans = min(ans, n * 2 - 1)
    print(ans)
t = int(input())
for _ in range(t):
    solve()