magic-password

Abid aur uske Bis Chor (Abid and his Twenty Thieves) was known for their cruel theft in City of Gold. This small battalion of thieves was so talented that once they even stole the State Treasury of the City.

Marcus, the King of City announced a very huge reward on Abid and his Twenty Thieves.  Robin was the head of operation and with his contacts all around the city helped him to capture this furious battalion within a few days.

The aim of this capture was to recover the stolen Gold from State Treasury. But Abid as soon as heard the reward on his battalion hid all of the stolen Gold into a cave.

The cave was a magical one ,  to open the door of cave one must say the Magic password. And the Magic Password is only known to none other than Abid. 

Somehow, Robin managed to get the Magic Password from Abid on crossword. While travelling to the cave Robin gone through a big Storm of Sand.

The storm rotated the crossword in Right and Left direction many times.

Now, Robin is in trouble and he needs your help to get the original Magic Password. He asked you for help.

Will you help Robin ? or will support Abid ?

Input : First line contains T number of Test-Cases. Next T lines contains three lines of input in each case. In first line is S the password written by Abid on crossword, second one contains number of rotation (N) caused by Storm and the third line represents the sequence of rotation R

Output : Your task is to find out the Minimum number of Swapping of letters that can give Robin the original Magic Password

Constraints

1 ≤ T ≤25

1 ≤ |S| ≤ 20

1 ≤ N ≤ 10

R = {L, R}

Note :  L -> Left Rotation and R-> Right Rotation

SAMPLE INPUT
1
aladin
5
R R R L R

SAMPLE OUTPUT
3

Explanation

Case 1; After rotations the string will be dinala. First swap can be dinala -> aindla and second swap will be aindla->alndia and final third swap will be alndia->aladin

Source: hackerearth | Difficulty: EASY


Solutions: