Under construction

Still being built. Things may change

Alex is Right

Time limit1sMemory limit1024 MB

Summary
Given two cities on a sphere, find the closest distance from the shortest great-circle flight to the North Pole and check whether it beats both endpoints.
Level

Medium6 of 10

Topics
Geometry, Math
Solved
No attempts yet

Problem

While on the first leg of their journey to Beijing (China) for the 2018 ACM ICPC World Finals, Alex and Timothy, two of the team members, were in a vigorous debate. The discussion was about their upcoming 13-hour flight from Washington, DC to Beijing. The question was whether the airplane would travel (a) west over the Pacific, (b) east over the Atlantic, or (c) north, then south, passing by the North Pole. Alex argued that the flight would obviously pass relatively close to the North Pole. Timothy, the self-proclaimed "Geometry Master", called this nonsense and said the pilots would never choose such a suboptimal route.

To Timothy's disappointment, once they landed in Washington, DC, Alex pulled up a flight map and showed Timothy, Arup, and Eric (who both supported Timothy's view) that their upcoming flight would indeed fly a route close to the North Pole.

Given the locations of two distinct points (cities) on the earth, calculate the minimum Euclidean distance between the airplane and the North Pole that will be achieved during the shortest possible flight around the surface of the earth between these two cities, and determine whether Alex's claim is correct. Assume that the airplane is a point on the surface of the earth at all times, i.e., the airplane does not have an altitude.

Alex's claim can be formally defined as follows: The minimum Euclidean distance from the airplane to the North Pole, while traveling along an optimal (shortest) flight around the earth, is strictly less than the distance from the North Pole to both the starting and ending points.

The Euclidean distance between two points (x_0,y_0,z_0)(x\_0, y\_0, z\_0) and (x_1,y_1,z_1)(x\_1, y\_1, z\_1) is defined as (x_0−x_1)2+(y_0−y_1)2+(z_0−z_1)2\sqrt{(x\_0 - x\_1)^2 + (y\_0 - y\_1)^2 + (z\_0 - z\_1)^2}. This is not the same as the arc distance that would need to be traveled along the surface of the earth.

To refresh your memory, below are the conversions from latitude and longitude to Cartesian coordinates on a sphere of radius RR:

x=R×cos⁡(latitude)×cos⁡(longitude)x = R \times \cos{(latitude)} \times \cos{(longitude)}

y=R×cos⁡(latitude)×sin⁡(longitude)y = R \times \cos{(latitude)} \times \sin{(longitude)}

z=R×sin⁡(latitude)z = R \times \sin{(latitude)}

Notes:

  • Use 6 3716\,371 km for the radius of the earth in your calculations.
  • The North Pole is located at 9090 degrees latitude and 00 degrees longitude.

Input

The first line of input consists of a single integer, TT (1≤T≤5001 \le T \le 500), the number of trips Alex and Timothy went on. Each trip consists of two input lines. The first line of each trip contains two space-separated real numbers, latitude and longitude (−90≤latitude<90-90 \le latitude < 90; −180<longitude≤180-180 < longitude \le 180), with exactly 66 digits after the decimal point, giving the latitude and longitude of the departure city. The second line of each trip contains the latitude and longitude of the destination city in the same format.

It is guaranteed that the departure and destination cities are at distinct locations (and not on the North Pole), and that there is exactly one shortest possible flight path between them.

Output

For each trip, output two lines. The first line is either Alex or Timothy, indicating who was right for this trip. The second line is the minimum Euclidean distance between the North Pole and the plane that is reached while flying from the departure city to the destination city. Print the answer with exactly 66 digits after the decimal point. An answer is accepted if its absolute or relative error is at most 10−610^{-6} km. Print a blank line after each trip.

Note #1: Use the value of PI (π\pi) provided by the library of your chosen language.

Note #2: It is guaranteed that in cases where Alex is right, the absolute difference between the minimum distance along the flight path to the North Pole and the minimum distance to the destination is at least 11 km.

Examples1

  1. Example 1

    Input
    2
    38.946474 -77.437568
    39.918620 116.443983
    16.000000 175.000000
    -45.000000 -93.000000
    
    Expected output
    Alex
    928.608923
    
    Timothy
    7668.327025