Under construction

Still being built. Things may change

2D Coordinate Conversion

Time limit1sMemory limit512 MB

Summary
For each test case, convert a point between Cartesian (x, y) and polar (r, theta) coordinates, with theta in the range [0, 2pi).
Level

Easy2 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

There are several ways to express the position of a point in two-dimensional space. The Cartesian coordinate system, which is widely used, expresses a point's position with a one-dimensional position along the x-axis and the y-axis. This problem introduces another way to express a point's two-dimensional position. For convenience, let the coordinates of point PP in the Cartesian coordinate system be (x,y)(x, y).

  • Polar coordinate system: Let the length of OP‾\overline{OP} be rr, and let θ\theta be the angle measured counterclockwise from the positive x-axis to OP→\overrightarrow{OP}. Then the coordinates of PP are (r,θ)(r, \theta). (r≥0r \ge 0; 0≤θ<2π0\le\theta\lt 2\pi) However, if r=0r=0, θ\theta is defined as 00.

Given the coordinates of PP in either the Cartesian or the polar coordinate system, convert them to coordinates in the other system.

Input

The first line contains the number of test cases TT. (1≤T≤1 000)(1\le T\le 1\,000)

Each test case consists of 2 lines, starting from the second line.

The first line of a test case contains the coordinate system number of the coordinates to convert. 1 is the Cartesian coordinate system, and 2 is the polar coordinate system.

The second line of a test case contains two real numbers aa and bb, given to eight decimal places, that represent the coordinates to convert. (a,b)(a, b) is (x,y)(x, y) in the Cartesian case and (r,θ)(r, \theta) in the polar case. (−100≤x,y≤100;(-100\le x, y\le 100; 0≤r≤100)0 \le r \le 100)

Output

For each test case, print on one line two real numbers that represent the converted coordinates.

An absolute or relative error of up to 10−610^{-6} is allowed.

Examples3

  1. Example 1

    Input
    2
    1
    1.00000000 2.00000000
    2
    2.23606798 1.10714872
    
    Expected output
    2.23606798 1.10714872
    1 2
    
  2. Example 2

    Input
    2
    1
    -1.00000000 -2.00000000
    2
    2.23606798 4.24874137
    
    Expected output
    2.23606798 4.24874137
    -1 -2
    
  3. Example 3

    Input
    2
    1
    0.00000000 0.00000000
    2
    0.00000000 0.00000000
    
    Expected output
    0 0
    0 0