Logo

Time limit1sMemory limit128 MB

Problem

Logo is a programming language built around a turtle. Commands in the language cause the turtle to move. The turtle has a pen attached to it, so as the turtle moves it draws lines on the page. The turtle can be programmed to draw interesting pictures.

We are interested in making the turtle draw a picture and then return to the point it started from. For example, we could give the turtle the following program:

fd 100 lt 120 fd 100 lt 120 fd 100

The command fd moves the turtle forward by the specified number of units. The command lt turns the turtle left by the specified number of degrees. Thus the commands above make the turtle draw an equilateral triangle with sides 100 units long, and after executing them the turtle ends up where it started. The turtle understands two additional commands: bk moves the turtle backward by the specified number of units, and rt turns the turtle right by the specified number of degrees.

After executing many commands, the turtle can get lost, far from its starting position. Your task is to determine the straight-line distance from the turtle's position at the end of its journey back to the position it started from.

Input

The first line of input contains one integer specifying the number of test cases to follow. Each test case starts with a line containing one integer, the number of commands to follow. The commands follow, one per line. Each test case contains no more than 1000 commands.

You can assume that each given degree is greater than or equal to 0 and less than 360.

You can also assume that each given distance is greater than 0 and less than 1000000.

Output

For each test case, output a line containing a single integer, the distance rounded to the nearest unit.

You can assume that the answer does not change within an absolute error of 0.01.