Medium Beginners Problems > Ad-hoc

IITROBO is the robot servant that cleans IIT using his own AI. The AI allows him to move forward one unit and rotate left or right 90 degrees. IIT wants to modify the AI that is given to IITROBO in such way that after cleaning, he will return there from where he started cleaning. As moving IITROBO costs a lot, returning to the starting place should need minimum number of commands to be executed by IITROBO. You will be given the commands following which IITROBO completed his cleaning. Your task is to determine minimum number of commands needed to send IITROBO back to his starting place. The only commands here are— F — this command moves IITROBO one-unit forward L — this command rotates him 90-degree left R — this command rotates him 90-degree right Given the starting position and sequence of commands IITROBO executed to perform his cleaning process, find the minimum number of commands needed to send him back to his starting position. Remember, IITROBO always starts cleaning facing to the East Input: ------ Input starts with an integer T (T ≤ 100) denoting the number of test cases. Each case starts with two integers x, y (0 ≤ x, y ≤ 1 000 000) denoting the starting location of IITROBO. The following line contains a sequence of commands with characters ‘L’, ‘R’, ‘F’. Length of the sequence won’t exceed 1000. Output: ------- For each case, print the minimum number of commands needed to send IITROBO back. Sample Input ------------ 2 0 0 FFRFFLFF 1 5 RFFFFLFFFFLFF Sample Output ------------- 8 7

Ariful Hoque Maruf