Many of us are familiar with graphing points on the x-y plane, also called the
Cartesian coordinate system. This system is quite intuitive to use - to locate
any point on the plane, we only must start at the origin, then move x units
along the x-axis and then move y units along the y-axis, and so coordinates
in this system are reported as (x, y).
There do exist other methods of defining points on the plane, with the
next most popular being the Polar coordinate system. To find a point on the
plane using this method we would again start at the origin and move r units
along the x-axis, but instead of moving directly upwards in y we instead
rotate around the origin counter-clockwise by θ degrees. And so coordinates
in this system are reported as (r, θ).
Two polar coordinates at (r=3, θ=60°) and (r=4, θ=120°)
Realize that while with the Cartesian coordinate system every (x, y)
coordinate pair with unique values of x and y corresponds to a unique point
on the plane, but this is not the case with the Polar coordinte system where
any point can be described with multiple coordinate pairs. For example the point
existing at (x, y) = (1, 0) in Cartesian coordinates would have valid Polar
coordinate equivalents of (r, θ) = (1, 0°), or (1, 360°), or (1, -360°), or
(-1, 180°), or (1, 1080°), etc. We can see that full revolutions (or
half-revolutions with inverted r) will land the point in the same spot.
You will be given many coordinate pairs in either Cartesian or Polar coordinates, and will be expected to return the same points described in the other coordinate system.
Note that all values of θ are in degrees for this problem.
Input Data
First line will be Q, the quantity of testcases.
Q lines will then follow with a single testcase each, either in the format
C x y or P r θ, where C or P indicate if the values are in Cartesian
or Polar coordinates, and the following two values are the coordinates of the
point.
Answer
Should consist of 2 * Q space-separated values, corresponding to the given
coordinates after being converted into the other coordinate system.
Error should be less than 1e-6
Example
input data:
5
C 0 3
C -1 1
P 3 60
P 4 210
P -1.234 -567.890
answer:
3 90 1.414214 135 1.5 2.598076 -3.464102 -2 1.090668 -0.577235