#C6825. Manhattan Distance Calculation

    ID: 50628 Type: Default 1000ms 256MiB

Manhattan Distance Calculation

Manhattan Distance Calculation

In this problem, you are given a number of test cases. For each test case, a robot is placed at the origin \( (0,0) \). The robot receives a string of instructions, where each character can be one of 'U', 'D', 'L', or 'R', representing moves up, down, left, or right respectively.

Your task is to compute the Manhattan distance \( |x|+|y| \) of the robot's final position from the origin after executing all instructions. The Manhattan distance is defined by the formula: \( d=|x|+|y| \), where \(x\) and \(y\) are the final coordinates.

Note: The input will be provided via standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The first line of input contains an integer \( T \) representing the number of test cases. Each of the following \( T \) lines contains a non-empty string that represents the movement instructions. Each character in the string is one of 'U', 'D', 'L', or 'R'.

Input Format Example:

2
UUDDLRLR
ULDRULDR

outputFormat

For each test case, output the Manhattan distance from the origin after executing the instruction string. Each result should be printed in a separate line.

Output Format Example:

0
0
## sample
2
UUDDLRLR
ULDRULDR
0

0

</p>