This page is still under construction.

Parts of this page are still being built. What you see may change.

Ecliptic

Time limit2sMemory limit256 MB

Summary
Given the axial tilt and the launchpad's latitude, find the first time after the reported equator crossing when the launchpad is closest to the ecliptic plane.
Level

Medium7 of 10

Topics
Math, Geometry, Implementation, Simulation
Solved
No attempts yet

Problem

The <>, an unmanned spacecraft, is stationed in the Northern Hemisphere at latitude ϕ\phi degrees and is ready to take off at any moment. The <> is to be put into a solar orbit, so it must be launched at a moment when the launchpad is nearest to the ecliptic plane.

The planet revolves around its sun along a circular orbit. The ecliptic plane is the plane containing this orbit. The planet is a sphere rotating around its axis. The angle between the planet's axis and the normal to the ecliptic plane is α\alpha degrees. The planet makes a full turn around its axis in 24 hours.

The control station is located on the planet's equator, at the same longitude as the <>. It crosses the ecliptic plane every 12 hours. At HH:MM:SS the control station reports crossing the ecliptic plane, and afterwards the control station and the <> are separated from each other by the ecliptic plane. Find the first moment after this report when the <> will be as close to the ecliptic plane as possible.

Input

The first line of the input file contains a single integer TT, the number of tests (1≤T≤1041 \leq T \leq 10^4). Each of the following TT pairs of lines contains a description of a consecutive test.

The first line of a test description contains two real numbers α\alpha and ϕ\phi. The number α\alpha is the angle between the rotation axis of the planet and the perpendicular line to the ecliptic plane, in degrees; the number ϕ\phi is the latitude of the spacecraft location, in degrees (1.0≤α,ϕ≤89.01.0 \leq \alpha, \phi \leq 89.0). Both real numbers are given with no more than five digits after the decimal point.

The second line contains the time of the incoming message from the control station. The time is given in the 24-hour format HH:MM:SS, where HH is the number of hours from 0 to 23, MM is the number of minutes from 0 to 59, and SS is the number of seconds from 0 to 59. Each of the three numbers contains strictly two digits, with possible leading zeroes.

Output

The output file must contain answers to the tests in the order of their appearance in the input, one answer per line.

An answer to a test is the nearest moment in time when the spacecraft can be launched. The time must be printed in the same format as the time in the message from the control station. The printed time must differ from the accurate answer by no more than one second.

Examples1

  1. Example 1

    Input
    2
    23.44 15.0
    12:00:00
    20.0 16.11
    23:00:00
    
    Expected output
    14:32:41
    02:30:04