This is first time I am submitting a solution. My code works fine for input given as sample. But I am getting WA a the end. Posting my code and output for sample.

# Problem Code: **POPGATES**

#code for persia

def code(li,k):

```
for i in range(k):
swap=0
if(li[-1]=='H'):
swap=1
li.pop()
#rightmost
if(swap==1):
for j in range(len(li)):
if(li[j]=='H'):
li[j]='T'
else:
li[j]='H'
print(li.count('H'))
```

t=int(input())

for i in range(t):

li=[]

line=input()

line.split()

n=int(line[0])

k=int(line[2])

line = list(input())

```
for j in range(len(line)):
if(line[j]=='H' or line[j]=='T'):
li.append(line[j])
print(li)
code(li,k)
```

### Example Input

```
3
5 3
H T T H T
7 4
H H T T T H H
6 1
T H T H T T
```

### Example Output

```
1
2
2
```