------
## 最终结论
```python
def max_score(t, test_cases):
    results = []
    for case in test_cases:
        n, k, s = case
        score = 0
        gaps = []
        current_gap = 0
        first_won_found = False

        # Calculate initial score and find gaps of L between W
        for i in range(n):
            if s[i] == 'W':
                if not first_won_found:
                    first_won_found = True
                    score += 1
                else:
                    if current_gap > 0:
                        gaps.append(current_gap)
                        current_gap = 0
                    score += 2
            else:  # s[i] == 'L'
                if first_won_found:
                    current_gap += 1

        # If no W at all, try to convert k L to W
        if not first_won_found:
            results.append(max(0, min(k, n) * 2 - 1))
            continue

        # Sort gaps to fill the smallest ones first
        gaps.sort()

        # Fill the gaps with available k changes
        for gap in gaps:
            if k >= gap:
                score += gap * 2 + 1
                k -= gap
            else:
                score += k * 2
                k = 0

        # Add remaining changes at the beginning or end of the sequence
        results.append(score + min(k, n - sum(gaps) - (score // 2)) * 2)

    return results


# Read input data and execute function
import sys

input_data = sys.stdin.read().split()
t = int(input_data[0])
index = 1

test_cases = []
for _ in range(t):
    n, k = int(input_data[index]), int(input_data[index + 1])
    s = input_data[index + 2]
    test_cases.append((n, k, s))
    index += 3

results = max_score(t, test_cases)
for result in results:
    print(result)
```